我最近将我的控制器代码更新为此创建
class MicropostsController < ApplicationController
before_filter :signed_in_user
def create
@micropost = current_user.microposts.build(params[:micropost])
if @micropost.review
params[:micropost].delete :review
@thread = Discussion.create!(params[:micropost])
else
@micropost.save
end
redirect_to root_path
end
当我使用上述内容时,它似乎在创建讨论或微博时起作用。但是,我相信使用“创建!” 不保存 user_id。当我查看讨论时,user_id 为零。我怎样才能将 user_id 与发帖者一起保存?
schema.db 中的表
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.timestamp "created_at", :null => false
t.timestamp "updated_at", :null => false
t.string "password_digest"
t.string "remember_token"
t.boolean "admin", :default => false
end
create_table "discussions", :force => true do |t|
t.string "content"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end