Given these params:
ex: 1
{:field => 'admin', :id => "1"}
ex: 2
{:field => 'client', :id => "1"}
ex: 3
{:field => 'partner', :id => "1"}
Is it possible, (and how of course) could i dynamically apply this to the User model such as:
controller
#note the field attribute is not a field
#the field attribute I'm trying to set above to what are given in the params hash
def update_user
field = params[:field]
@user = User.find(params[:id])
@user.field = !@user.field
@user.save(false)
render :nothing => true
end
fyi
Why not just send a has with params and update the with update_attributes(params[:user])? Because the users attributes are protected and it’s just easier to update a boolean this way.
I would do something like this:
(The “include?” is a security check to prevent users from choosing some other field you don’t want them to)