1

I have a form in Rails 3 that must be submitted with a normal post, like this

<%= form_for @seller, :as => :seller_user, :url => save_seller_url do |f| %>

but one of the field inside needs to execute a remote ajax call to update some value, like this one

<%= f.select( ... ) %> => on change please make a remote call to fill new data here

I did not found any documentation online to add the :remote => true option to the select helper, am I missing something?
what is the correct way of handling this?
Thank you

1 Answer 1

1

I wrestled with this for a while too. I think the best "rails way" to do it is like:

<%= form_tag(controller: "sellers", action: "your_controller_action") do %>
    OTHER FORM STUFF HERE
    <select name="some_select" id="some_select" onchange="your_javascript_function">
        <option> ... </option>
    </select>
    OTHER FORM STUFF HERE
    <%= submit_tag("Submit") %>
<% end %>

Then in your controller to handle the submit, you can refer to this field like normal, as params[:some_select]

This assumes your controller is called sellers_controller. More about form_tag here and form_tag helpers here

Sign up to request clarification or add additional context in comments.

2 Comments

therefore you are suggesting not to use the select helper function and to handle the ajax call manually in the javascript handler linked to the onchange event?
yes. only because i feel like the ease outweighs the hassle of trying to do it with form_for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.