I need help with rendering a partial called 'colordata' after selecting a color from a dropdown list using Ajax. Unfortunately, I'm not seeing any changes on the main page and the form is undefined in the colordata partial.
This is the schema of my Order model:
create_table "orders", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "design"
t.integer "quantity"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "color"
t.string "lotnumber"
t.float "consumption", limit: 24
t.string "number"
end
Here's the Ajax call:
$("select[name='order[color]']").change(function(){
$.ajax({
url: "colordata",
type: "post",
data:{
"color": $(this).val()
},
dataType: JSON,
success: function(data){
}
});
});
This is the controller:
def colordata
request.POST.each do |key, value|
@color = value
end
@lotdetail= Master::Yarn.where('color like?', @color)
respond_to do |format|
format.js
end
end
The Colordata.js.erb file:
$(".lot").innerHTML += "<%= escape_javascript(render(partial: 'colordata'),locals: {form: form) %>"
The partial _colordata.html.erb:
<%= form.label :lotnumber %>
<%= form.collection_select(:lotnumber, @lotdetail, @lotdetail.lotnumber,@lotdetail.lotnumber,prompt: "Select the Yarn")%>
The errors encountered are:
- Form is not defined in _colordata.html.erb
- The partial is not appending into the class lot.
Thank you for your assistance.