Pregunta

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

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top