現在簡易ブログを作成していますがそこにCARRIERWAVEを使用して
画像をUPできる様進めています。
この作業を行っている中
undefined method `avatar?' for nil:NilClass
というエラーがhelperに出ました。
profile_imgapp/helpers/application_helper.rb module ApplicationHelper def profile_img(user) return image_tag(user.avatar, alt: user.name) if user.avatar? unless user.provider.blank? img_url = user.image_url else img_url = 'no_image.png'
現在view _form.html.erは下記のとおりです
<div class="field"> <%= profile_img(@user) if profile_img(@user) %> <%= f.file_field :avatar %> <%= f.hidden_field :avatar_cache %> </div>
ぐぐったところcontrollerに必要な事がかけている様子ですが
http://stackoverflow.com/questions/35165167/undefined-method-avatar-for-nilnilclass
具体的にどの様なコードを書いたらいいかわからず・・・(><)
たぶんcontllerにuserの設定がされていないのが原因と思いますが
どなたかヒントをご教授頂ければ幸いです、、、、
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/19 01:25
2017/05/20 04:03