[英]Issue with passing params in link_to rails
I'm having trouble passing a param through a link_to in Rails using the below code: 我在使用以下代码通过Rails中的link_to传递参数时遇到麻烦:
<%= link_to new_registration_path, {:workshop => @workshop.id } do %>
When I pry into the controller, the :workshop is not being included in the params (only controller and action). 当我撬入控制器时,:workshop并未包含在参数中(仅包含控制器和操作)。
Is this a strong params issue? 这是一个强大的参数问题吗?
The workshop
param has to be passed to the new_registration_path
helper instead of passing it to link_to
, like this: workshop
参数必须传递给new_registration_path
帮助器,而不是传递给link_to
,如下所示:
<%= link_to new_registration_path(workshop: @workshop.id) do %>
If you want the URL to be like /something/123
instead of /something?workshop=123
, you can change how your route is defined on routes.rb
: 如果您希望URL类似于
/something/123
而不是/something?workshop=123
,则可以更改在routes.rb
上定义路由的方式:
get something/:workshop
and then you can pass workshop: 123
to the URL helper. 然后您可以将
workshop: 123
传递给URL帮助器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.