ruby on rails - Load dynamic partial based on Dropdown selection -
i new ruby on rails. please guide me this. tried code doesn't know correct or wrong. i'm loading collection of @customer based on customer have load fields in same form. suppose 1 customer have name,password,agent,address , customer have different attributes.
i first create jquery calls display have tried load dynamic partial file. please load dynamic partial file based on customer.
here code
app/views/customer/new/_form.html.erb <%= simple_form_for(@customer) |f| %> <%= f.input :first_name, placeholder: 'first name', label: 'customer first name' %> <%= f.input :last_name, placeholder: 'last name', label: 'customer last name' %> <%= f.input :email, placeholder: 'user@domain.com', label: 'customer email' %> <%= f.input :customer_id, :collection => customer.all, :prompt => "choose ats",:input_html => {:onchange => "load_customer_content(this)"} %> <div id="customer_content%> </div> <%end%> <script> function load_customer_content(customer){ $("#customer_content").html("<%= escape_javascript(render partial: customer.find(customer.value).name.to_s%>"); } </script>
but partial not merging div of customer_content. believe using ajax can achieve not sure how trigger ajax help???