NoMethodError in Home#topとエラーが表示されます。undefined method `image' for nil:NilClassとまた表示されています。users_helper.rbの記述がおかしいようで、そのときの記述は
module UsersHelper
def image_for(user)
if user.image ←ここの部分がおかしいそうです
image_tag "/user_images/#{user.image}", class: "profile_img"
else
image_tag "kikirara.png", class: "profile_img"
end
end
end
のようになっています。
そこでNoMethodErrorですからhome_controller.rbにimage_for(user)メソットを記述したのですが、またエラーが出てしまい、メソットが使われていないことが問題なのではないことがわかりました。
どこにどう記述するべきなのでしょうか?
ちなみにhome_controller.rbは
class HomeController < ApplicationController
def top
if user_signed_in?
# 変数@noteにNoteクラスのインスタンスを代入してください
@note = Note.new
# 変数@notesにNoteクラスのインスタンスの配列を降順で代入してください
@notes = Note.all.order(created_at: :desc)
else
@message = "ようこそKotoritterへ!"
end
end
def about
end
end
のようになっています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。