1

I saw this post about adding parameters to a member action route:

Rails3 Routes - Passing parameter to a member route

And the routing works great when I enter the full URL manually: www.whatever.com/resource/:resource_id/action/:action_parameter

Is there a convenient path helper I can use to link to this in my views? For example, if it is just an ordinary member action WITHOUT a parameter, I can use

action_resource_path(:resource_id)

Is there an equivalent with the extra parameter?

Community
  • 1
  • 1
James
  • 11
  • 1
  • 2

1 Answers1

4

You can specify a url helper with the as option:

resources :foos do
  collection do
    get 'bar/:resource_id', :action => :bar, :as => 'bar'
  end
end

The route that gets generated will look like:

$ rake routes | grep bar
bar_foos GET    /foos/bar/:resource_id(.:format)         {:action=>"bar", :controller=>"foos"}

You can use that like:

bar_foos_path(:resource_id => @resource.id)
jdeseno
  • 7,753
  • 1
  • 36
  • 34