0

I'm new to state_machine and am trying to use it to model a job application process.

For a given state, there are possible events that can be triggered by the applicant or by the employer. Is there a way to tag an event to indicate this? For instance, I'd like to be able to get a list of all of the transitions that could be triggered by an employer so when the employer is logged in she can see only the available actions that an employer could take on an application.

Or if there is a better to model this, I'd love to know.

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
Nick Sedlet
  • 109
  • 1
  • 1
  • 6

1 Answers1

0

You can use an additional gem like cancan todo some authorisation on this methods.

I had a related problem a few days ago and got this nice answer:

Is it possible to use cancan in a model?

I come up with something like this:

# view
...
<% user.state_transitions.each do |transition| %>
  <% if can? "#{transition.event}".to_sym, User %>
    <%= link_to transition.event, user_path(user, user: {:state_event => transition.event}), :method => :put%>
  <% end %>
<% end %>
...

You have to check this also in the controllers update method.

Community
  • 1
  • 1
tonymarschall
  • 3,862
  • 3
  • 29
  • 52
  • there's a direct method `user.state_events` which returns all the position events that can be called from the current state. – Musaffa May 03 '14 at 12:02