Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@kajirikajiri

Passing Variable to Partial - undefined local variable or method error 2つの解決法

techブログ

1: render partial 'my_partial' と書いているか、render 'my_partial' と書いているか確認する

呼び出し方に違いがあります

<%= render 'my_partial', :locals => {:class_Name => "Science", :y => 36} %>
<% render partial: 'my_partial', :locals => {:class_Name => 'Science', :y => 36 } %>

2: 定義されているか確認する

# Rails4以降
<% if defined?(local_var) do %>
# Rails3
<% if local_assigns[:local_var].present? do %>

自分の場合、partialに書いた変数を使わない場合があり、 if defined?(local_var)を書いたら解決した。defined?で確認して、local_varをそのまま使わないようにした。

参考

自分はqiitaの記事のおかげで解決しました
https://qiita.com/shinichinomura/items/1921027fc28279ce54e0
https://stackoverflow.com/questions/16229470/passing-variable-to-partial-undefined-local-variable-or-method-error/21651848#21651848

0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?