Rails 4查询字符串链接

时间:2014-07-26 08:28:47

标签: ruby-on-rails-4

所以我有这个查询字符串

<a href="/reports/user?q=<%= current_user.id %>">
# => /reports/user?q=1

在rails 3中运行良好,但抛出

Couldn't find Report with id=user

使用rails 4。

#routes.rb
get "reports/:field" => "reports#search"

1 个答案:

答案 0 :(得分:1)

你在这里路线

get "reports/:field" => "reports#search"

将使用search

调用params = {field:"user"}方法

如果您希望它使用相同的网址,请将路由更改为:

get "reports/user" => "reports#search"

并在search中使用q代替field

将链接更改为

<a href="/reports/<%= current_user.id %>">