Is possible something like:
@users = User.criteria.for_ids(params[:user_ids])
@users.update_all(:suspend => true)
instead of:
for u in @users
u.suspend = true
u.update_attributes
end
Take a look at this:
# Updating one record:
Person.update(15, :user_name => 'Samuel', :group => 'expert')
# Updating multiple records:
people = { 1 => { "first_name" => "David" }, 2 => { "first_name" => "Jeremy" } }
Person.update(people.keys, people.values)
Seen here: http://apidock.com/rails/ActiveRecord/Base/update/class
Updates an object (or multiple objects) and saves it to the database, if validations pass. The resulting object is returned whether the object was saved successfully to the database or not.
In your case:
User.update(params[:user_ids], :suspend => true)
Hope this helps!
As long as for_ids method returns a criteria(instead of an array), you can use update_all.
@users = User.criteria.for_ids(params[:user_ids])
@users.update_all(:suspend => true)
The update_all call gets translated in to a set call. Refer to the documentation for more details.