As the title says, I am trying to load a form partial with an AJAX request; one of the fields in my form requires a variable in the controller so it can create the select dropdown menu. If I render the partial directly in the view, it accesses the variable fine but when I separate the partial and try to load it via an AJAX request, it doesn't know how to find the variable.
I have tried following the answer found here (giving it to the partial as a local variable) but it still does not work.
@headers is the variable that is not being loaded.
partial:
= simple_form_for(Constraint.new, html: {:multipart => true, autocomplete: "off", :class=> "form-horizontal" }, remote: true, :authenticity_token => true) do |f|
div.profile-details
br
= f.select :header, @headers.each{|header|} , input_html:{:class => "user-update"}, label: "Header", :prompt => "Select a Header"
br
= f.button :submit, "Save Constraint"
.js file that loads partial:
$(".newConditionContainer").append('<%= escape_javascript(render 'projects/rulesConstraintsInput')%>');
UPDATE:
I ended up defining the variable in the controller method that calls the js request. I had earlier assumed that the variable was accessible but it was only being defined in a method outside of the partial.