Reputation: 7001
I've put this method in my controller so I can lock users documents, but the record of each document remains unchanged.
def lock
@doc = Doc.find(params[:id])
respond_to do |format|
params[:locked] = true
format.html { redirect_to share_path(@doc) }
format.json { render json: @doc }
end
end
I know the params[:locked]
is the part that isn't working. What would the correct syntax be? I've tried @doc.update_attribute(:locked, true)
without success, too.
Cheers.
Upvotes: 0
Views: 1693
Reputation: 20649
Params is a hash of attributes submitted through your form. It is not related to database and is not saved anywhere. In fact, you are only supposed to read data from it, not modify it. To update a record you should call methods on the record itself such as save
or update_attribute
.
So @doc.update_attribute(:locked, true)
should work in your case.
Upvotes: 2