각 기사에 user_ids 추가 (유증) :나는 사용자 모델을
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable has_secure_password has_many :articles
그리고 User
내 스키마는 다음과 같습니다 이들의
create_table "users", force: true do |t| t.string "first_name" t.string "last_name" t.string "email" t.string "password_digest" t.datetime "created_at" t.datetime "updated_at" t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" end
절반이 고안 출신 보석. 그래서 내가 성취하고자하는 것은 각 기사에 그것에 할당 된 저자가있는 것입니다 (first_name + last_name).
belongs_to :topic
belongs_to :user
def author
"#{self.user_id.first_name} #{self.user_id.last_name}"
end
그리고 문서 컨트롤러의 내 행동은 다음과 같습니다 :
내 문서 모델 같은 외모
def create
@article = Article.new(article_params)
@article.user = current_user
if @article.save
#@article.user = session[:user_id]
flash[:notice] = "Article has been uploaded"
redirect_to(:action => "show", :id => @article.id)
else
flash[:notice] = "Please fill in all fields."
render("new")
end
end
그리고 내 쇼보기에서 <p><%[email protected]%></p>
을 할 경우, 그것은라는 오류가 정의되지 않은 메서드 - 'first_name'
각 기사에 작성자를 추가하려면 어떻게합니까? 대신 저자 방법을 self.user_id.first_name.in의
, 나도 몰라. – xoshi827