Update select tag dynamically with ajax in rails

前端 未结 1 1203
终归单人心
终归单人心 2021-02-05 13:14

I have two dropdowns in a view, and I\'m attempting to update the second dropdown options based on the selected value from the first dropdown.

I am aware of the Railscas

相关标签:
1条回答
  • 2021-02-05 13:56

    Add escape_javascript to escape carrier returns, single and double quotes that get generated by options_from_collection_for_select.

    I do not see any other problems except adding call to escape_javascript. Please try the following in your js.erb:

    <% if @filterProducts  %>
        $('#product_id').html("<%= escape_javascript options_from_collection_for_select(@products, :id, :name) %>");
    <% end %>
    
    0 讨论(0)
提交回复
热议问题