I have a problem with link_to to send a variable. It works fine with the form_for and submit button, but I need to send data using link_to.
This works fine with form_for:
<%= form_for (@post), :method => :post, :remote => true, :html => { :id => "#{@post.id}" }, :url => { :controller => "posts", :action => "follow", :post_id => post.id } do |f| %> <%= f.submit "Follow" %> <% end %>
This does not work: (:
<%= link_to post_path(@post), :method => :post, :remote => true, :html => { :id => "#{@post.id}" }, :url => { :controller => "posts", :action => "follow", :post_id => post.id } do%> <em></em> <%= "Follow" %> <% end %>
This is the last one, link_to does not send parameters, and my controller does not receive parameters and receives the error type InvalidFind (Calling Document # find with nil is invalid):
Edited by:
Now I found a solution ... the parameters should be set to the target, Parameter:
<%= link_to post_path(:post_id => post.id), :method => :post, :remote => true, :html => { :id => "#{@post.id}" }, :url => { :controller => "posts", :action => "follow" } do%>
source share