0
게시물, 사용자 (Devise의 인증) 및 댓글이있는 블로그를 만들고 있습니다. 사용자가 게시글에 댓글을 쓰면 그의 이름 위에 자신의 이름을 표시하고 싶습니다. 어떻게해야합니까?게시 할 댓글 (레일스)을 작성한 사용자의 이름을 표시하는 방법
class Comment < ActiveRecord::Base
attr_accessible :post_id, :text
belongs_to :post
belongs_to :user
end
class User < ActiveRecord::Base
has_many :posts, :dependent => :destroy
has_many :comments, :dependent => :destroy
validates :fullname, :presence => true, :uniqueness => true
validates :password, :presence => true
validates :email, :presence => true, :uniqueness => true
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :fullname
end
class Post < ActiveRecord::Base
attr_accessible :text, :title, :tag_list
acts_as_taggable
validates :user_id, :presence => true
validates :title, :presence => true
validates :text, :presence => true
belongs_to :user
has_many :comments
end
답장을 보내 주셔서 감사합니다.하지만 제가 작성한 후에는 댓글 옆에있는 사용자 이름이 여전히 비어 있습니다. 내 쇼 파일에서 나는 comment.user 메소드를 사용한다. 맞아? – user2596615
아마도 <% = Comment.user.fullname %> – XanderStrike
을 찾고있을 것입니다. 나는 코멘트 컨트롤러에 user_id를 추가하는 마이그레이션을 만들었습니다. 어쨌든 도움 주셔서 감사합니다. – user2596615