行,所以我都用了这个代码我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