简体   繁体   中英

How to send a parameter in form_tag in rails

I want to send a parameter in form_tag helper like we can send a parameter through link_to helper in rails like this:

<%= link_to("Send Invitation", {:controller => 'l_home', :action => 'sendConnectRequest', foo: "hello world!!!"}, :class => "btn-primary")%>

Similarly I am trying to do this <%= form_tag({:action => "sendConnectRequest", :method => 'post', foo: "hello world!!!"}) do %> in order to send a parameter in form_tag, but it is not working :(

Help needed

Thanks

I'm sure there's a couple of ways to do this but the first that popped in my head. I think the easiest approach is to simply place the data you want in a hidden field inside the form_tag . Like so:

<%= form_tag ...your form_tag params... do %>
    <%= hidden_field_tag :foo, "hello world" %>
<%end%>

That will get sent to the server accessible by params[:foo] .

Here's some documentation regarding the hidden_field_tag .

Hope that helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM