Ruby | Pass Collection_select to partial via Locals =>

Viewed 23

I'm trying to pass the selected value of a f.collection_select to a partial view. The render partial statement by itself works fine, but the 'locals' isn't selecting the collection properly

<%= 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'></div>
<% end %>

<script>
    function updateSpecificForm(selected_val) {
        $('#specific_form').html('<%= j render partial: 'layouts/foo', :locals => {:partialCode => @Code } %>')
        $('#specific_form').show();
    }
</script>

Render partial statement works fine without the locals{}, but when I try to assign those locals in the partial view, or surface them to check, with something like:

<% @partialCode = locals[:partialCode] %>
    <%= f.hidden_field :partialCode, :value => @partialCode %>

, I get:

ActionView::Template::Error (undefined local variable or method `locals' for #<#<Class:0x000000000da0edc8>:0x000000001c0c8ea8>

Or if I skip the assignment and just say <%= f.hidden_field :partialCode, :value => partialCode

It is an empty string

0 Answers
Related