Reputation: 33
Ok this one is going to sound really trivial but I can't seem to get it right. I just want to pass a parameter :invite_code with the link_to from the view to an un-related controller.
view:
<td><%= link_to 'Join', :action => 'invite', :invite_code => project.invite_code , :method => :post %></td>
routes:
match 'invite' => 'database#invite', :via => :post
database_controller:
def invite ...
puts params
end
The debug output on the console goes as follows:
{"_method"=>"post", "authenticity_token"=>"..........", "action"=>"invite", "controller"=>"database"}
Everything works fine except that I can't seem to pass the the parameter. I am rookies but I have been stuck on this way too long.
Thanks!
Upvotes: 3
Views: 2099
Reputation: 4880
Try the following:
<%= link_to "Join", invite_path(invite_code: project.invite_code), method: :post %>
You might need to update your route:
post 'invite' => 'database#invite', as: :invite
Upvotes: 3