Felix Felix - 2 years ago 67
Ruby Question

rails passing a local variable to a partial got some errors

I'am trying to pass a local variable to a partial, but I got this error:

undefined local variable or method `blubb' for #<#<Class:0x00000007cb8c00>:0x00000007c79f78>

My code looks like this:

<% rate = Rating.where(["comment_id = ? and movie_id = ?", comment.id, @movie.id]) %>

<% @ratingvalue = rate[0][:ratingvalue] %>

<div class="col-md-3 text-right"><%= render :partial => "shared/starRating", :locals => {blubb: @ratingvalue} %> </div>

When I inspect @ratingvalue there is my integer value inside.

Then in the partial I try to do this:

<%= blubb %>

but then I got the error.

also tried this:

<%= :blubb %>

but then only blubb is printed ...

What is going wrong?

Thanks for your help.

Answer Source

This code look fine, Btw you can try this:

<%= render :partial => "shared/starRating", :object => @ratingvalue %>

and in the partial you can using @ratingvalue variable.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download