行,所以我都用了這個代碼我users_controller更新的動作,這是在生產和工作,我想知道這條線是做什麼是此行中我的Rails應用程序做
@user.attributes = { 'role_ids' => [] }.merge(params[:user])
和我不明白這是怎麼設置role_ids,如果有更好的方法來做到這一點
@user是用戶與不必須在它role_ids .attributes那麼,這如何工作....這裏是我的關係
class Role < ActiveRecord::Base
has_many :users, :through => :role_users
has_many :role_users
class User < ActiveRecord::Base
has_many :roles, :through => :role_users
has_many :role_users
class RoleUser < ActiveRecord::Base
belongs_to :role
belongs_to :user
end
和PARAMS是
Parameters: {"utf8"=>"✓", "authenticity_token"=>"GV/BbOZdKn7SkzD8zydceVdwA+fga=", "user"=>{"id"=>"629", "company_id"=>"1", "active"=>"1", "role_ids"=>["1", "3", "1"], "notification_ids"=>["1", "2", "3"]}, "company"=>"11", "id"=>"621"}
所以params [:user]被修改 – Trace 2012-04-10 13:56:03
編輯我的答案,請看看。 – Vik 2012-04-10 13:58:58
沒有參數[:用戶]不會改變,它會返回新的散列。在控制檯上試試相同的東西 – Vik 2012-04-10 14:07:08