2012-05-25 17 views
7

usar joya state_machine - Officialhuman_name para el estado de la gema de rubí state_machine

Cada estado puede tener 'nombre humano'. Por docs y APIs que he intentado:

en my_model.rb

state_machine :initial => :new do 
    state :new, :human_name => 'Added and not accepted' 
    ... 

en my_view.haml

%p= MyModel.human_state_name(@item.state_name) 
%p= @item.human_state_name 

ambas variantes regresan simplemente 'nuevo' en lugar de 'Alta y rechazado' . ¿Qué debería hacer? He cometido un error al configurar human_name o al obtener human_name?

Actualizar Obras en:

en: 
    activerecord: 
    state_machines: 
     mymodel: # model name 
     states: 
      new: 'Added and not accepted' # state name 

Respuesta

9

que no es necesario pasar: human_name opción a máquina de estados. Simplemente defina las traducciones para su idioma:

en: 
    activerecord: 
    state_machines: 
     mymodel: # model name 
     state: # state name 
      states: 
      new: 'Added and not accepted' 
      events: # you can also define translations for the events 
      some_event: 'put custom translation here' 
+0

Funciona con otra sintaxis =) ¡Muchas gracias! – dmr

Cuestiones relacionadas