Wallace and Gromit
Wallace and Gromit

Reputation: 59

Rails - calling a partial

My question is so simple that I am hesitating to ask. (Why are all examples provided in the documentation unnecessary complicated?)

I want to transfer the title section for my rails project in a partial (DRY...). Very much simplified, the calling line in my show.html.erb is:

<%= render "shared/headerblock", locals: {cntrnm: @cntrlst.CountrName } %>

Let's reduce the code in the partial _headerblock.html.erb to the absolute minimum:

My Countryname is <%= cntrnm %>

Rails complains (even without the plain text containing the passed variable):

undefined local variable or method 'cntrnm' ...

What's wrong? (BTW: also just passing a string instead of the instance variable from@cntrlst produces this error.)

As far as I can see, I just copied what I found in all kinds of tutorials and blogs. - - - Obviously not ;-)

Upvotes: 0

Views: 395

Answers (1)

leafeve
leafeve

Reputation: 150

rails have 2 cases It's up to you

Case 1:

<%= render partial "shared/headerblock", locals: {cntrnm: @cntrlst.CountrName } %>

Case 2:

<%= render "shared/headerblock", cntrnm: @cntrlst.CountrName %>

Upvotes: 1

Related Questions