Mass assignment was designed to protect precisely against what you're trying to do here so ideally speaking, you should add it to a whitelist (attr_accessible
) if you need to modify it.
However, there are a few issues with your controller action that will need to be addressed even if you get the isactive
attribute whitelisted.
@job.update_attribute(:isactive = true)
is not valid. update_attribute
does not handle assignments, the correct syntax is update_attribute(attribute, value)
so it should be:
@job.update_attribute(:isactive, true)
Also, the update_attribute
method calls save on the passed object. Calling @job.save
after update_attribute
(provided there is no other code assigning attributes) is redundant.
A better way to write this method would be:
def approve
if @job.update_attribute(:isactive, true)
redirect_to(:action => :show)
flash[:notice] = "Job Approved"
else
render 'show'
end
end
However, if you cannot modify the model and are not worried about callbacks or validation, you can update the database column directly with update_column
(or update_columns
in Rails 4):
def approve
if @job.update_column(:isactive, true)
redirect_to(:action => :show)
flash[:notice] = "Job Approved"
else
render 'show'
end
end