Note that there are some explanatory texts on larger screens.

plurals
  1. POpartial local only accessible using local_assigns, not exposed by name
    text
    copied!<p>I am passing two locals from a view ERB to a partial. Both locals are successfully passed in local_assigns. However, I am only able to use the FormBuilder via a local variable name in the partial. The other value is usable within my partial as local_assigns[:disable_edits], but not as disable_edits.</p> <p><strong>_form.html.erb</strong></p> <pre><code> &lt;div&gt; &lt;%= f.fields_for :panels do |builder| %&gt; &lt;%= render "panel_fields", :f =&gt; builder, :disable_edits =&gt; true %&gt; &lt;% end %&gt; &lt;/div&gt; </code></pre> <p><strong>_panel_fields.html.erb</strong></p> <pre><code>&lt;div&gt; &lt;p&gt; &lt;%= local_assigns[:disable_edits] %&gt; &lt;/p&gt; &lt;p&gt; &lt;%#= disable_edits ? 'disable edits true' : 'disable edits false' %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= local_assigns.keys %&gt; &lt;/p&gt; </code></pre> <p></p> <p>local_assigns[:disable_edits] results in "true" being displayed.</p> <p>local_assigns.keys results in "[:f, :disable_edits, :panel_fields]" being displayed.</p> <p>Uncommenting the ternary statement results in "undefined local variable or method `disable_edits' for #&lt;#:0x4d58768>"</p> <p>I am following what I understand is the latest suggested Rails syntax, but have tried manipulations using :partial=>, :locals=>, :as=>, etc. to no avail. I also do not think I've made this an optional argument in any way, so a lot of the information about testing with has_key vs. nil? isn't helping me. My understanding is everything in local_assigns should be exposed as in the partial as a local variable with the same name as the hash key.</p> <p>I'm getting by for now using local_assigns[:disable_edits], but would like to understand what is happening and correct things so I can use more conventional syntax. Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload