You have many possibilities to pass params — :submit, :with, :url — with functions like — link_to_remote, remote_function, observe_field and more.
I have the following code, a select box and an ajax button. I’m trying to send to the controller both the selected value, and the text.
1 2 3 | <p id="users_form" class="likep"> <%= select_tag("initiators_users", options_from_collection_for_select(User.find_all, "id", "login")) %>; <%= button_to_function("Adaugare din lista", remote_function(:submit => "users_form", :url => {:action => "userlist"})) %>; |
:submit
,
Rails says it “Specifies the DOM element ID that‘s used as the parent of the form elements. By default this is the current form, but it could just as well be the ID of a table row or any other DOM element.”. But when debugged it passes only
1 | Parameters: {"action" => "userlist", "controller" => "tasks", "initiators_users" => "1"} |
:url
has more possibilities to pass any kind of extra parameters:
1 | :url => { :action => "my_action", :param1 => "text1", :param2 => "text2"} |
but my problem was that I could not replace “text1″ with DOM object values.
:with
has the possibility to pass a JavaScript string as a valid URL query string, so finally I have
1 | :with => "'obj=' + $('initiators_users').options[$('initiators_users').selectedIndex].text + '|' + $('initiators_users').value", |
which produces params like
1 2 | username1 | id1 username2 | id2 |
[UPDATE]
You can combine the above possibilities for passing params:
1 2 3 4 5 6 | <%= observe_field("record_orgchart", :update => "job_description_relations", :url => {:action => "get_relations", :id => @record.id}, :with => "'orgchart=' + value") %> |


