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?
a source to share
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.
a source to share
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.
a source to share