【问题标题】:How to determine link_to path arguments for nested resources?如何确定嵌套资源的 link_to 路径参数?
【发布时间】:2010-10-28 15:47:20
【问题描述】:

如何确定 show、edit 和 destroy 的 link_to 参数?我知道“新”是“new_user_post_path”。不过,似乎没有其他东西遵循这个约定?

我的相关路线.rb sn-p:

resources :users do
      resources :posts
end

【问题讨论】:

    标签: ruby-on-rails-3


    【解决方案1】:

    跑步

    rake routes
    

    您的 rails 根目录应该会告诉您您需要了解的路线名称和预期参数。

    【讨论】:

    • 所以它只是将“_path”附加到路由名称?我仍然遇到路由错误,但我想此时这实际上不是路由问题。
    • 没错,如果 'rake routes' 给你一个名为 new_post 的路由,那么你可以使用 new_post_path 或 new_post_url。
    • 我认为这并不总是适用于 rake 路线,至少在 rails 3.1 中不再适用,如果 rake 路线为您提供:“client_prescription”,您需要添加一个“s”来复数处方,然后添加_path,像这样:client_prescriptions_path
    猜你喜欢
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多