ruby - Multiple Select Tag in Rails -
I am trying to implement a multiple level drop down list in the rail. I have three tables in my DB.
vehicle_make. RB
class vehicle make & lt; ActiveRecord :: Base validates_uniqueness_of: making has_many: end of placements
vehicle_model.rb
class vehicle models & lt; ActiveRecord :: Base validates_uniqueness_of: Model has_many: Appointments end
vehicle_make_model.rb
Class VehicleMakeModel & lt; ActiveRecord :: Base validates_uniqueness_of: vehicle_make_id ,: scope = & gt; : Vehicle_model_id end
and im trying to implement a multi dropdown list should select the vehicle model in appointments.html.rb only to make it. P>
& lt;% = f.select: vehicle_make_id, options_for_select (vehicle_make.map {| s | [s.make, s.id]}, appointment. Vehicle_make_id), {}, {class: "Form-control"}%> ;
And in my JS I have ..
$ ('# appointment_vehicle_make_id'). ('Change', function () {var vehicle_make_id = This.value; $ .ajax ({url: '/ appointments / update_models', type: 'GET', data: {make_id: vehicle_make_id}, success: function ) {Console.log (feedback);}}};});
And this is my controller method.
def update_models @vehicle_models = VehicleModel.all @model_ids = [] @selected_vehicle_models = VehicleMakeModel.where (vehicle_make_id: params [: make_id]). Order (: vehicle_model_id) until the consultation [: make_id] .blank? @ Selected_vehicle_models.each do | T | @model_id & lt; & Lt; T.vehicle_model_id end response_to do | Format | Format.html {render layout: false} format.js end
end
I have an HTML page named update_models.html .erb related to the above action.
and lt;% = select_tag: vehicle_model_id, options_for_select (@ model_ids.map {| s | [s.model, s.first.id]}, zero), {}, {class : "Form-reproduction"}%>
I get an error in the terminal
ActionView :: Template :: error (wrong number of arguments (1.3 for 4)): 1: & Lt;% = select_tag: vehicle_model_id, options_for_select (@ model_ids.map {| s | [s.model, s.first.id]}, zero), {}, {class: "form-control"}% & gt; ;
I got stuck here. I do not know how to move from here .. please
In your controller action, update_models
, you are trying to render JS, so it is trying to find a template called update_models.js.erb
.
Block your response_to
with:
Do not Answer Format | Format.json {Render: Jason = & gt; After this, you will need to parse this data in your AJAX Success Callback
Comments
Post a Comment