'RubyOnRails Auto submit when changed

I added this:

onchange: 'this.form.submit();'

to this:

<%= f.select :rank, 1..3, {}, {class: 'form-control selectpicker', data: {'live-search' => 'true'}, onchange: 'this.form.submit();' } %>

and I'm getting this error message:

ActionController::UnknownFormat in PlanController#create_or_update

but when when I go back my list is updated with my selection, so it is working?? How do I fix this?

These are the lines that are causing the error...

if success
      respond_to do |format|
        format.js { @attempted_update ? render('sample_update') : render('sample_create') }
      end
    else
      @model = @sample_model
      respond_to do |format|
        format.js { redirect_to sample_path(sample_name_1: session[:sample_name2]), notice: render_to_string('sample_plan2') }
      end


Solution 1:[1]

It is because you have not specified the html format in respond to. You only specify format.js but when you run your web application from a web browser you have to specify format.html, too, because that's the format the client expects.

Something like this:

respond_to do |format|
  format.html { redirect_to sample_path, notice: 'Record successfully created.'}
end

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user3309479