Borbat Borbat - 2 years ago 171
jQuery Question

Rails Select Tag - passing an argument to controller

Recently I've encountered a problem with passing parameters from view to the controller using select tag. Here is the code:


<%= select_tag 'users',options_from_collection_for_select(User.where(id: @users.ids), "id", "email", params[:users].blank? ? : params[:users]), :onchange => "this.form.submit();", class: 'form-control pull-right' %>

What I want is to pass the ID of the chosen user to the hash params in order to reload the page again, this time with the chosen user data.

In console I got this error:

heimdall:280 Uncaught TypeError: Cannot read property 'submit' of null

I will be very happy, if u help me.

Answer Source

Please be make sure select_tag added inside form_tag or form_for view helper.

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download