こんにちは。
表題の件です。
投稿一覧をクリックしたときにエラーがでます。
内容は以下です。
NoMethodError in Notes#index
undefined method `image' for nil:NilClass
関連コードは以下です。
◆note.controller.rb◆
def index
@notes = Note.all
end
◆users_helper.rb◆(imageはヘルパーで定義しています)
module UsersHelper
def image_for(user)
if user.image
image_tag "/user_images/#{user.image}", class: "profile_img"
else
image_tag "wanko.png", class: "profile_img"
end
end
end
◆_note.html.erb◆(imageメソッドはここで呼び出してます。)
<li> <%= image_for(note.user) %> <span class="user-name"> <%= note.user.name %> </span> <span class="content"> <%= link_to note.title, note_path(note.id) %> </span> </li>◆index.html.erb◆(userファイルです。)
<h1 class="heading">ユーザー一覧</h1> <%= link_to '新規ユーザー作成', new_user_path, class: "btn add-user-btn" %> <ul class="user-list"> <% @users.each do |user| %> <li> <%= image_for(user) %> <%= link_to user.name, user %> | <%= user.email %> </li> <% end %> </ul>ご回答よろしくお願いします!!!!!
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/08/23 09:26
2016/08/23 10:15
2016/08/23 10:18