#15 new
Deleted User

DOC : Automated adding routes + custum action bar

Reported by Deleted User | March 22nd, 2009 @ 05:41 PM

This is for the readme :

  • To reduce the coding work when you modify your state machine, you can ignore the routes.rb file !

you can code your route as :


  map.resources :customers, :member => {}.merge(Customer.aasm_events.inject({}) {|acc, v| acc[v.first] = :put; acc})

and rails insert your routes for you ! To add your special action insert it between the first {] before .merge .

  • To display a action bar you only have to create a partial in this case, named action :

In the view insert :


<%= render :partial => "action", :object =>@customer %>

create _action.erb partial :


  <%  action.aasm_events_for_current_state.each do |state| -%>
    <%=  link_to(t(".link_#{state.to_s}"),eval("#{state.to_s}_#{action.class.to_s.underscore}_path(action)"), :method => :put)%> |
  <% end -%>

Only the allowed actions are displayed This last code is adapted from a code found in a forum, but I don't remember the URL. All credits are going to this first contributer.

Hope this can help any other rail coder.

regards Serge

No comments found

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Library for adding state machines to Ruby classes. Includes persistence layers for things like ActiveRecord. Formerly known as acts_as_state_machine.

People watching this ticket

Pages