の協会くださいイム、私は、ユーザーがそれぞれの記事の下に掲示される名前だった私はTwitterのような投稿できるアプリケーションを作成しようとしているユーザーとポスト
マイPost_controllerこの
def index
@posts = Post.all(:order => "created_at DESC")
@users = User.find(:all)
#@user_id = current_user.find(params[:id])
respond_to do |format|
format.html
end
end
def create
@post = current_user.posts.create(:message => params[:message])
@user.id = current_user.username
end
のように見えます
モデルには正しい関連付けがあり、テーブルにはUserテーブルのUser_idとPostテーブルのForeignテーブルがあります。インデックスビューに投稿と名前を表示する方法を作成するにはどうすればいいですか?
そのエラーが表示されることはありません名前の属性としてのユーザーテーブル –
私たちは、2つのモデルクラスのコードを表示し、db – p0rter
の列は 'create_table" posts "、:force => true do | t | t.text "メッセージ" t.datetime "のcreated_at"、:ヌル=> falseを t.datetime "updated_atの"、:ヌル=> falseを t.integer "USER_ID" 終了 CREATE_TABLE "ユーザー"、: force => true do | t | t.string "ユーザ名" t.string "電子メール" t.string "password_hash" t.string "password_salt" t.datetime "のcreated_at"、:ヌル=> falseを t.datetime "updated_atの"、: null => false 終了 ' ' Post.rb has-belongs_to:user' User.rb has_many:user –