저는 레일을 처음 사용합니다. 나는 질문을 올리기로 결정하기 전에 대답을 찾고 있었다. 내가 찾은 2 개의 답은 나를 위해 일하지 않았다.사용자 이름 rails devise
그래서 "post"및 "devise"모델이 설치 및 구성되어 있습니다.
는 I 사용자다음 관계
사용자에 "이름"을 추가 -> 많은 포스트있다 -> 사용자에 속한다.
하지만 막혔습니다.
게시물과 함께 렌더링 할 때 정확히 사용자 이름을 검색합니까?
< % = post.user.username = %>?
그 밖의 무엇을해야합니까?
post.rb
class Post < ActiveRecord::Base
attr_accessible :postbody, :posttitle
validates_presence_of :postbody, :posttitle
belongs_to :user
end
user.rb은 class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
has_many :posts
end
귀하의 질문, 문제점에 대해 구체적으로 설명하십시오. – swapab
문제는 게시물이 생성 된 사용자 이름을 렌더링하려고합니다. 게시물 옆에 표시됩니다. – igrec