开发者

Rails - Member Action with Parameter - path helper?

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 ac开发者_如何转开发tion WITHOUT a parameter, I can use

action_resource_path(:resource_id)

Is there an equivalent with the extra parameter?


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜