How do I set the extra field in rails?
Here are the models
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
And my schema
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
I have these params
Parameters: {"user"=>{"id"=>"", "first_name"=>"some", "last_name"=>"name",
"phone_number"=>"", "email"=>"something@gmail.com", "active"=>"true",
"company_ids"=>["186"], "role_ids"=>["2"], "notification_ids"=>["1", "2", "3"]}}
THE PROBLEM I am running into is the positions.regular_user is always true when i do
@user.update_attributes(params[:user])
or the
@user = User.new(params[:user])
if @user.save
pprobably because it defaults to true.... But i need to change to false if role_ids is > 3
any ideas on how to change the default flag