Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

human_name for state in state_machine ruby gem

I use gem state_machine - Official

Each state can have 'human name'. By docs and APIs i've tried:

in my_model.rb

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

in my_view.haml

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

both variants return just 'new' instead of 'Added and not accepted'. What I should do? I've made mistake in setting human_name or in getting human_name?

Update Works in:

en:
  activerecord:
    state_machines:
      mymodel: # model name
        states:
          new: 'Added and not accepted' # state name
like image 964
dmr Avatar asked May 25 '12 10:05

dmr


1 Answers

You don't need to pass :human_name option to state machine. Just define translations for your language:

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'
like image 61
melekes Avatar answered Nov 04 '22 22:11

melekes