0

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.

6
  • 2
    make the variable ratingvalue a instance variable in viewer does not make sense. Commented Apr 19, 2016 at 13:06
  • Have a look at the way you can render partials in rails 4 Commented Apr 19, 2016 at 13:10
  • 2
    The code looks fine, except for the old style notation - could you post the partial code itself in case there is something missing from the context? Commented Apr 19, 2016 at 14:10
  • in partial is only this: <%= blubb %> Commented Apr 19, 2016 at 15:11
  • 1
    @Felix - Hmm, your code is perfectly working for me. Can you post all your views file code (maybe you forget something, or you have 2 partial views...)? Because I tested your code on Rails 4.2.4 and everything working well Commented Apr 19, 2016 at 15:58

1 Answer 1

1

This code look fine, Btw you can try this:

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

and in the partial you can using @ratingvalue variable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.