Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

DOC : Automated adding routes + custum action bar

#15

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

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

State: new
Milestone: none
Assigned to: Scott Barron Scott Barron

Activity

No comments yet.

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.