小编Pan*_*ium的帖子

Rails 3 polymorphic_path - 如何更改默认的route_key

我得到了配置CartCartItem(belongs_to :cart)模型.

我想做的是打电话polymorphic_path([@cart, @cart_item])让它使用cart_item_path,而不是cart_cart_item_path.

我知道我可以更改的路线生成的URL /carts/:id/items/:id,但是这不是我感兴趣的.此外,重命名CartItemItem是不是一种选择.我只想cart_item_path在整个应用程序中使用方法.

提前感谢任何提示!

只是为了表明我的观点:

>> app.polymorphic_path([cart, cart_item])
NoMethodError: undefined method `cart_cart_item_path' for #<ActionDispatch::Integration::Session:0x007fb543e19858>
Run Code Online (Sandbox Code Playgroud)

所以,为了重复我的问题,我能做些什么polymorphic_path([cart,cart.item])来寻找cart_item_path而不是cart_cart_item_path

routing ruby-on-rails-3

6
推荐指数
2
解决办法
1841
查看次数

标签 统计

routing ×1

ruby-on-rails-3 ×1