こんにちは。
表題の件です。
エラーが起きます。
なんとか、自力で奮闘してみましたが、謎が解けません。
これをやってみてはどうか?という提案だけで構いません。
アドバイスをいただきたいです。
おそらく問題になっているコードは以下です。
▼ターミナル上のコメント▼
ActionView::Template::Error (undefined method image' for nil:NilClass): 1: <li> 2: <%= image_for(note.user) %> 3: <span class="user-name"> 4: <%= note.user.try!(:name) %> 5: </span> app/helpers/users_helper.rb:4:in
image_for'
app/views/notes/_note.html.erb:2:in _app_views_notes__note_html_erb___364350041_93410860' app/views/home/top.html.erb:7:in
_app_views_home_top_html_erb___625327124_94711520'
おそらく、3つのファイルの中のコードのどこかに問題があるのではないでしょうか?
①users_helper.rb
②_note.html.erb
③top.html.erb
ということで、該当コードを載せていきます。
①users_helper.rb
module UsersHelper
def image_for(user)
if user.image
image_tag "/user_images/#{user.image}", class: "profile_img"
else
image_tag "pokemon.jpg", class: "profile_img"
end
end
end
②_note.html.erb
<li> <%= image_for(note.user) %> <span class="user-name"> <%= note.user.try!(:name) %> </span> <span class="content"> <%= link_to note.title, note_path(note.id) %> </span> <span> <%= note.created_at.strftime("%Y-%m-%d %H:%M:%S") %> </span> </li>③top.html.erb
<% if user_signed_in? %>
<aside class="sidebar"> <%= render 'notes/form' %> </aside> <ul class="notes"> <h2>投稿の一覧</h2> <%= render @notes %> </ul> <% else %> <div class="top-wrapper"> <%= image_tag "pokemon.jpg" %> <div class="register-wrapper"> <h1><%= @message %></h1> <%= link_to "新規登録", new_user_registration_path, class: "btn btn-large register-btn" %> </div> </div> <% end %>以上です。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/08/30 06:19