I have a model that is stateful. In each state there are a selection of actions that the user might want to perform on an instance of the model. Currently I am translating the model state to actions that get represented in the view using a view helper.
Something like this... in the model:
Class Thing
def state_is_A?
state == 'A'
end
end
In the helper:
def display_available_actions(thing)
if thing.state_is_A?
link_to <action1>
link_to <action2>
end
end
And in the view:
<%= display_available_actions(@thing) %>
I don't like the fact that the model state is translated into view actions in the helper. I would like this to be incorporated into the model. On the other hand, it doesn't seem healthy for the model and view to get so coupled.
Is there a Ruby or Rails idiom that suits this kind of situation better than my approach? Should each state be a separate model perhaps?