Passing Variable to Partial - undefined local variable or method error

ruby-on-rails

Solution

I've noticed that if I did not include 'partial:' before my partial path, like so:

<%= render 'my_partial', :locals => {:class_Name => "Science", :y => 36} %>

I was required to use the hash+symbol in my partial to access the desired values as others have noted.

<div>
<h1> <%= locals[:class_Name] %> has a y value of <%= locals[:y] %></h1>
</div>

However, including 'partial:' before my partial path:

<% render partial: 'my_partial', :locals => {:class_Name => 'Science', :y => 36 } %>

...allowed me to simply call the hash values directly.

<div>
<h1><%= class_Name %> has a y value of <%= y %></h1>
</div>

Just something to keep in mind, this issue tripped me up for awhile when trying to send the locals hash to my partial.

Problem

Here is the code in my view to call the partial: ``` <%= render(:partial => "tabs", :locals => {:class_Name => "Science", :y => 36}) %> ``` and now here is what's in _tabs.html.erb: ``` <div> <h1> <%= class_Name %> </h1> </div> ``` I expect HTML output of: ``` <div> <h1> Science </h1> </div> ``` But instead I get the error: ``` undefined local variable or method `class_Name' for #<#<Class:0x007f873b156c28>:0x007f873b1f9540> ``` I have closed and restarted Aptana (the IDE I use), and restarted the server multiple times Thanks in advance for your time.

Original source