How can I send additional parameters to the link / button_to_remote call?

The Ajax prototype takes a "parameters" parameter with a hash array for the parameters ( prototype doc ), which is automatically sent as GET or POST, but I couldn't find how to add items to that array using Rails' button_to_remote method.

I could just add parameters to the url sent to the method, but that seems hacky. Is there a better solution out there?

+1


a source to share


3 answers


I actually found a solution! You can pass parameters to functions using the: with option, for example:

<%=button_to_remote "+3", {:url =>task_path(@project, @story, task), :with=>"'actual=3'"}%>

      

The trick is that the value for: with is a javascript expression that should return a URL-formatted key-value pair, such as "key = value". This is why there are extra quotes around the value for the same.



The function can also be used to pull information from a page, if needed:

:with=>"getValuesForPostbackFunction()" 

      

The function will be evaluated before the form is submitted.

+3


a source


Using button_to_remote

, the only way to send parameters to the next action is to put them in a URI.

button_to_remote

intended as a functional equivalent link_to_remote

that also has no other way to add parameters.



If you require a smaller-scale control, you need to create a complete form and submit this action.

+1


a source


Add hidden input fields in the form you call button_to_remote.

<input type="hidden" name="name" value="myValue">

      

0


a source







All Articles