モデルはこちら
class User < ActiveRecord::Base
has_many :companies, :through => :positions
has_many :positions
class Company < ActiveRecord::Base
has_many :positions
has_many :users, :through => :positions
class Position < ActiveRecord::Base
belongs_to :company
belongs_to :user
attr_accessible :company_id, :user_id, :regular_user
end
そして私のスキーマ
create_table "positions", :force => true do |t|
t.integer "company_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "regular_user", :default => true
end
私はこれらのパラメータを持っています
Parameters: {"user"=>{"id"=>"", "first_name"=>"some", "last_name"=>"name",
"phone_number"=>"4074615519", "email"=>"something@gmail.com", "active"=>"true",
"company_ids"=>["186"], "role_ids"=>["2"], "notification_ids"=>["1", "2", "3"]}}
私が直面している問題は、positions.regular_user が常に true であることです。
@user.update_attributes(params[:user])
または
@user = User.new(params[:user])
if @user.save
おそらく、デフォルトでtrueになっているためです....しかし、role_idsが> 3の場合はfalseに変更する必要があります
デフォルトフラグを変更する方法に関するアイデア