users_helper.rbで定義したメソットをhome_controller.rbのtopアクションで呼び出したいです。
users_helper.rbには
ruby
1module UsersHelper 2 def image_for(user)←ここが重要 3 if user.image 4 image_tag "/user_images/#{user.image}", class: "profile_img" 5 else 6 "background: #ccc" 7 end 8 end 9end
と、
home_controller.rには
ruby
1class HomeController < ApplicationController 2 include UsersHelper 3 def top 4 if user_signed_in? 5 # 変数@noteにNoteクラスのインスタンスを代入してください 6 @note = Note.new 7 # 変数@notesにNoteクラスのインスタンスの配列を降順で代入してください 8 @notes = Note.all.order(created_at: :desc) 9 view_context.image_for(user)←ここが重要 10 @users = User.all 11 else 12 @message = "ようこそKotoritterへ!" 13 end 14 end 15 16 def about 17 end 18 19 def timeline 20 @timeline=Timeline.all 21 end 22end
と記載しました。
そうすると、
NameError in HomeController#top
undefined local variable or method `user' for とエラーが出ました。
userをどこかに定義すれば良いのでしょうか?
home_controller.rbとかにでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。