Rails - 带参数的成员操作 - 路径助手?

发布于 2024-12-04 13:50:48 字数 396 浏览 4 评论 0原文

我看到这篇关于向成员操作路由添加参数的文章:

Rails3 Routes -将参数传递给成员路由

当我手动输入完整的 URL 时,路由效果很好:www.whatever.com/resource/:resource_id/action/:action_parameter

有没有方便的路径助手我可以在我的观点中使用链接到此吗?例如,如果它只是一个没有参数的普通成员操作,我可以使用

action_resource_path(:resource_id)

是否有与额外参数等效的操作?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑忘罢 2024-12-11 13:50:48

您可以使用 as 选项指定 url 帮助器:

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

生成的路由将如下所示:

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

您可以像这样使用它:

bar_foos_path(:resource_id => @resource.id)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文