I am trying to change all of the default_standing fields to FALSE for all other records when someone marks one as TRUE. That way I will only ever have one default record in the table. Here is what I am doing in both create and update in my controller, but it doesn't seem to be working:
def update
@standing = Standing.find(params[:id])
if @standing.default_standing
@standings = Standing.where(["default_standing = ? AND id != ?", true, params[:id]])
@standings.each do |s|
s.default_standing = false
s.save!
end
end
respond_to do |format|
if @standing.update_attributes(params[:standing])
format.html { redirect_to(@standing, :notice => 'Standing was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @standing.errors, :status => :unprocessable_entity }
end
end
end