Martin
Martin

Reputation: 11336

Why is this partial call not passing its locals values

I tried the following code to render a partial

= render partial: 'movie_same', locals: { current: @movie }, collection: @movie.dvd.movies.order('scene')

But I get this error

NameError in Movies#show
Showing /Users/user/app/views/movies/_movie_same.html.haml where line #1 raised:
undefined local variable or method `locals' for #<#<Class:0x007fe713ba90a8>:0x007fe710f79a00>

The mention in the render file is just to locals[:current].

Any idea why I'm getting this error?

Upvotes: 0

Views: 73

Answers (1)

HungryCoder
HungryCoder

Reputation: 7616

You do not need to use locals[:current] in the partial. You just need to use current as :locals will set it as local variable in the target partial. so it will be just

current

This is what is said from the doc

would provide the @buyer object to the partial, available under the local variable account

<%= render :partial => "account", :locals => { :account => @buyer } %>

Upvotes: 1

Related Questions