The main error I’m getting is that the method ‘course’ is not found.
Is there something that I have to do differently when using a partial?
I’m thinking that I can’t access the ‘course’ using #{course.whatever}
in a partial, but I’m not sure how to access it.
Your problem is that course isn’t in the scope of the partial. By
default, the only variable that will get automatically passed is an @
variable that has the same name as the partial itself. If you want to
pass course into the partial, you need to amend your render call:
The main error I’m getting is that the method ‘course’ is not found.
Is there something that I have to do differently when using a partial?
I’m thinking that I can’t access the ‘course’ using #{course.whatever}
in a partial, but I’m not sure how to access it.
Any help would be much appreciated.
Thanks.
Your local variable you set up before you call the partial are out of
scope, and do not exist within the partial. Instance would exist, but
you shouldn’t set instance variables in your view. The right is to tell
partial to provide values for the local variables.
<% for course in @courses %>
<%= render :partial => “class_list”, :locals => {:course => course} %>
<% end %>
Your problem is that course isn’t in the scope of the partial. By
default, the only variable that will get automatically passed is an @
variable that has the same name as the partial itself. If you want to
pass course into the partial, you need to amend your render call: