-2

I want to create a link_to with the name of the controller, action and also pass additional arguments. The method type is post Currently, I have:

<%= link_to "Name", {controller: "users", action: "custom"}, method: "post" %>

How do I pass in additional arguments to the above? If it's not possible to do this with a link_to, what are my other options?

user1175969
  • 540
  • 6
  • 19
  • 3
    Here is a fantastic post on this, i definitely have used this in the past. Although passing data through a link_to is not ideal, it works well enouugh.. http://stackoverflow.com/questions/1898737/pass-parameter-by-link-to-ruby-on-rails – Richard Jul 06 '16 at 18:14

3 Answers3

0

you can pass more parameters inside the {}

<%= link_to "Name", {controller: "users", action: "custom", first_parameter:"foo", second_parameter:"bar"}, method: "post" %>
xploshioOn
  • 4,035
  • 2
  • 28
  • 37
  • I tried that. But the params are being included in the URL. Is there a way I can avoid that? I don't need to necessarily use a link_to – user1175969 Jul 06 '16 at 18:31
  • oh, you mean pass those parameters like there are inputs in a flied... that can not be done, at least not in a simple way like that. you need to create a form for that or make an ajax request. – xploshioOn Jul 06 '16 at 18:36
0

If you want to do POST then you should be using button_to, with the default POST behavior (though, you don't have to):

<%= button_to "Name", { controller: "users", action: "custom", param1: "param1", param2: "param2" } %>
0

You can use the hidden_field_tag

Chetan Datta
  • 447
  • 9
  • 19