Jerome
Jerome

Reputation: 6217

rails partial not processing locals

The following view is calling a partial and declaring locals for it in a way that is consistent with the Rails guides:

<% @wines_for_winetype.each_with_index do |wine, index| %>
  <%= render 'price_table', locals: {wine: wine} %>

But this is generating an error

undefined local variable or method 'wine' for #<#:0x00007fba1fb97298> Did you mean? @wine @wines

Yet in the dev mode with the live shell the following: enter image description here demonstrates that the locals exist.

Why are they not being handled in the view partial according to expected syntax? how should this me fixed?

Upvotes: 2

Views: 80

Answers (2)

noordean
noordean

Reputation: 106

@mrzasa is right. If you want to omit the partial keyword, then you need to omit the locals keyword too.

<%= render 'price_table', wine: wine %>

Upvotes: 2

mrzasa
mrzasa

Reputation: 23347

You missed the partial keyword:

<% @wines_for_winetype.each_with_index do |wine, index| %>
  <%= render partial: 'price_table', locals: {wine: wine} %>

Upvotes: 4

Related Questions