如何覆盖自定义路由的 :path_names
我已经用英语实现了 RESTFUL 路线,但该应用程序是针对德国用户的,因此应该将路线重命名为德语。我使用 :path_names 选项和 CRUD 路由来完成此操作,但这不适用于我自己创建的路由。例如,模型 SingleBudget
具有从 n..n 关联中删除特定对象的操作。在我的routes.rb
中,它看起来像这样:
resources :single_budgets, :path => 'einzelbudgets', :path_names => { :new => 'neu', :edit => 'aendern', :remove => 'entfernen' } do
collection do
get ':id/remove' => "single_budgets#remove", :as => :remove
end
end
它适用于新建和编辑操作,但不适用于删除操作。有人知道如何解决它吗?
I've implemented RESTFUL routes in english but the application is for german users so the routes should be renamed to german. I did this using the :path_names option and for the CRUD routes but this doesnt work for the routes I created on my own. For example the model SingleBudget
has an action that removes specific objects from a n..n association. In my routes.rb
it looks like this:
resources :single_budgets, :path => 'einzelbudgets', :path_names => { :new => 'neu', :edit => 'aendern', :remove => 'entfernen' } do
collection do
get ':id/remove' => "single_budgets#remove", :as => :remove
end
end
It works for the new and edit action but not for the remove action. Does anybody have an idea how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
:path_names
参数只会影响内置的 CRUD 操作。对于您的自定义操作,只需在get
参数中将其命名为您想要的名称即可:这将为您提供一个指向
/single_budgets/:id 的
,它将执行控制器中的remove_single_budgets
路径/entfernenremove
方法。The
:path_names
parameter will only affect the built-in CRUD actions. For your custom actions, just call it what you want right in theget
parameter:This will give you a
remove_single_budgets
path that will point to/single_budgets/:id/entfernen
, which will execute theremove
method in your controller.