I am trying to render a partial upon change in the drop down list. There is the onchange javascript function which directs to a link to display the corresponding form.
But here I am getting a #<ActionController::UnknownFormat: ActionController::UnknownFormat> error inside the get_template method in controller.
I suppose it is something to do with calling the link through javascript, as the request is processed as HTML.
Processing by XYZController#get_template as HTML
How to process it as JS ?
Here's the detailed code.
dropdown.html.erb
<div id="requests_dropdown">
Choose the type of request : <%= select_tag 'drop_request_id', options_for_select(@request_types.map{|x| [x[:name], x[:id]] } ) %>
</div>
Javascript
<script>
$('#drop_request_id').on('change', function() {
var request_type_id = $('#drop_request_id').val();
var href = 'get_template/' + request_type_id ;
window.location = href;
});
</script>
controller
def get_template
@request_type = [x,y,z]
respond_to do |format|
format.js
end
end
get_template.js.erb
$("#request_form_partial").html("<%= escape_javascript(render partial: 'request_form', locals: { request_type: @request_type } ) %>");
window.location = hrefinstead of an AJAXgetcall?