Ruby Form Partials with Locals

Viewed 24

Ok, trying to break up a form into separate erb files, I've seen others on here successfully passing the form variable into the render partial locals => {}, but for whatever reason, it's being a real stick in the mud for me. Let's see who can fix this 'undefined local variable or method `f' for #<#Class:0x0000000018a619a0:0x000000002c119910>' error:

<% @modName = locals[:moduleName] %>
<% @record = locals[:record] %>
<% @id = locals[:id] %>
<% @OpNo = locals[:opno] %>
<% @modLower = locals[:moduleName].downcase %>

<%= form_for Command.new do |f| %>
    <%= f.collection_select(:Code, Command.where(FLD: @modName), :Code, :Definition, options ={prompt: true }, html_options = {:onchange => "updateSpecificForm(this.value)", :id=> "command_Cmd"}) %>
    <%= f.hidden_field :mod, :value => @modName %>
    <br /><br />
        <div id='specific_form' style='display:none'>
            <%= render :partial => 'layouts/' + @modLower, :locals => {:f => f} %>
        </div>
<% end %>

<script>
    function updateSpecificForm(selected_val) {
        $('#specific_form').show();
    }
</script>

then the partial (which is where 'f' isn't recognized):

<%= f.hidden_field :mod, :value => @modName %>
    <%= f.label :year, 'Year' %>
        {more form stuff}
        <%= f.submit 'Approve' %>
    </div>
0 Answers
Related