【问题标题】:Getting param in controller from GET request in Ruby on rails从 Ruby on rails 中的 GET 请求获取控制器中的参数
【发布时间】:2013-09-11 13:59:50
【问题描述】:

我在 routes.rb 中有

namespace :point do
  resources :points do
    get 'history'
end

在视图中:

= link_to 'History', point_point_history_path(object)

网址看起来像“/point/points/123456/history”

但在控制器中我无法得到它:

def history

raise params[:id].inspect

end

它返回 nil。

我做错了什么?

【问题讨论】:

    标签: ruby-on-rails routes param


    【解决方案1】:

    生成的路由是

    point_point_history GET    /point/points/:point_id/history(.:format)    point/points#history
    

    所以你想请求params[:point_id],而不是params[:id]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多