3
I need to reference the field numbers status
of the database, which are in the format ENUM
, with the names of my model
.
What’s the best way to do that?
models/item.Rb
class Item < ActiveRecord::Base
# definir constantes
PUBLICADO = 1
SUSPENSO = 2
SOMETHING = 3
# ???
end
controllers/list.Rb
class ListaController < ApplicationController
# preciso buscar algo assim:
Item.status
Item.status.publicado
Item.status.suspenso
Item.status.something
end
has something here : http://rails-bestpractices.com/posts/708-clever-enums-in-rails
– Rod