views:

883

answers:

5

Prototype's Ajax accepts a parameter called 'parameters' with an hash array for parameters (prototype doc) which would automatically be sent as GET or POST vars, but I could not find how to add items to that array using the Rails button_to_remote method.

I could just add the parameters to the URL sent to the method, but that feels hackish.. Is there a better solution out there?

A: 

Add hidden input fields in the form that you're calling the button_to_remote on.

<input type="hidden" name="name" value="myValue">
b. e. hollenbeck
Thanks for the reply, but there's no way to add an input tag in the form, because there's no form. button_to_remote creates a prototype Ajax object, without a form.
Eduardo Scoz
+1  A: 

Using button_to_remote the only way to send parameters to the next action is putting them into the URI.

button_to_remote is intended as a functional equivalent of link_to_remote, which also has no other way of adding parameters.

If you need more fine-grained control, you need to build the full form and submit that to your action.

Jakob S
You're right. But it seems silly to not have a way of adding those parameters..
Eduardo Scoz
I actually found a way of passing extra parameters, check out my answer on my question!
Eduardo Scoz
+2  A: 

I actually found the solution! You can pass parameters in the function using the :with option, like this:

<%=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 key-value pair in the URL format, like "key=value". That's why there's extra quotes around the value on the same above.

A function could also be used to pull the information from the page, if necessary:

:with=>"getValuesForPostbackFunction()"

The function will be evaluated before the form is submitted.

Eduardo Scoz
A: 

The way of passing key value pairs is not working

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

Can you suggest any other way out to solve this problem?

aashish
Strange, it works fine here.. Can you show the HTML that gets generated from your method?
Eduardo Scoz
If you have further problems and some more information, what exactly doesn't work, post it as a new question ("Ask Question" button in the top right of the page). More people will see your question that way.
sth
A: 

thanks!! helped me !!

dewdrops