以下のコードで...
<%= image_tag comment.user.avatar.url(:medium), class: "circle-extrasmall" %>
<%= comment.user.name %>
エラーが発生します...
undefined method `avatar' for nil:NilClass
ユーザーとコメントの適切な関連付けを作成できたと思います。
これがコントローラーの中身です...
class CommentsController < ApplicationController
def create
@challenge = Challenge.find(params[:challenge_id])
@comment = @challenge.comments.create(params[:comment])
@comment.user_id = current_user
flash[:notice] = "Comment has been created!"
redirect_to @challenge
end
end
モデルの内容は次のとおりです...
class Comment < ActiveRecord::Base
attr_accessible :challenge_id, :user_id, :text
validates :user_id, presence: true
belongs_to :challenge
belongs_to :user
end
しかし、何がそのエラーの原因なのかわかりません。Ruby-on-Rails は初めてです。ご提案いただきありがとうございます。