데이터베이스 및 모델 스키마
사용자 2.3.3 (ID, 이름, 이메일)
게시물 (ID, 제목, 메시지, USER_ID)
특정 게시물을 생성 한 사용자의 name
을 어떻게 표시합니까?
#posts controller #index action - retrieves all posts in descending order. #I also want it to retrieve user information of that post def index @posts = Post.all(:order => "created_at DESC") respond_to do |format| format.html end end
#partial _post.html.erb Posted by "??how can show the user name here??"
나는 액티브 레코드 협회와 user.rb
및 post.rb
를 수정하고 외부 키를 설정했습니다. 즉 post.user_id
참조 user.id
.
그러나 index
작업에서 개별 게시물에 대한 사용자 정보를 표시하려면 어떻게해야합니까?
감사합니다 :) 나는 그와 같은 것이고 그렇게 빨리 대답 해 주셔서 감사 할 것입니다. – Mike
http://adwords.google.co.kr/home.html http://railscasts.com 및 http://asciicasts.com (railscasts의 텍스트 버전) 정말 좋은 레일 튜토리얼. –