これをグーグルで検索すると、Rails コア チームが Rails 4 のソリューションに取り組んでいることがわかりますが、それはまだ先のことです。
Users
とCircles
は互いにhas_and_belongs_to_many
関係があります。
私のスキーマは次のようになります。
create_table "circles", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "circles_users", :force => true do |t|
t.integer "circle_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "password"
end
しかし、私のコードでは、circles_controller
これをやろうとすると:
def create
@circle = Circle.new(params[:circle])
@circle.users << User.find(session[:user].id)
...
ブラウザに次のエラーが表示されます。
SQLite3::ConstraintException: circles_users.created_at may not be NULL: INSERT INTO "circles_users" ("circle_id", "user_id") VALUES (11, 5)
ここで虚偽であるcreated_at
ことについてどうすればよいですか?updated_at