使用link_to方法rails 3将变量发送到控制器
我有一个link_to发送变量的问题。 使用form_for和submit按钮工作正常,但我需要使用link_to发送数据。
这适用于form_for:
:post, :remote => true, :html => { :id => "#{@post.id}" }, :url => { :controller => "posts", :action => "follow", :post_id => post.id } do |f| %>
这不起作用:(:
:post, :remote => true, :html => { :id => "#{@post.id}" }, :url => { :controller => "posts", :action => "follow", :post_id => post.id } do%>
最后,link_to不发送参数,我的控制器没有收到参数并得到错误类型InvalidFind(调用文档#find with nil无效):
编辑:
我现在找到了一个解决方案……必须将params设置为target-参数:
post.id), :method => :post, :remote => true, :html => { :id => "#{@post.id}" }, :url => { :controller => "posts", :action => "follow" } do%>
你发送params与任何url/路径助手。 只需传入这样的哈希键/值对。
<%= link_to post_path(@post, :my_param => "param value"), .... %>