用于保存“房间”信息的控制器代码:
params[:room][:session_id] = session.session_id
=> 17: respond_to do |format|
18: if current_user.create_room(params[room_params])
19: format.html { redirect_to '/rooms/#{@new_room.id}'}
在语句17显示之前检查“ room_params”:
1] pry(#<RoomsController>)> room_params
=> <ActionController::Parameters {"name"=>"uma7",
"session_id"=>"2_MX40NjIxOTU5Mn5"} permitted: true>
但是“插入”语句仅存储user_id,而不存储“ session_id”和“ name”。
INSERT INTO "rooms" ("created_at", "updated_at", "user_id") VALUES
($1, $2, $3) RETURNING "id" [["created_at", "2018-12-25
17:18:14.300732"], ["updated_at", "2018-12-25 17:18:14.300732"],
["user_id", 6]]
user_id是Rooms表中的外键。
为什么current_user.create_room(params[room_params])
不保存'session_id'和'name'值?谢谢