Hello all…I understand how dirty objects work and have gone into
script/console and successfully tried it. What I don’t understand is how
I can use it in an application. All references to its use are via
console.
I want to send an email when someone changes a field in the record. I
would think I could do this with the ‘update’ method in the controller:
def update @log = Log.find(params[:id])
if @log.update_attributes(params[:log]) #flash[:notice] = “Successfully updated log.”
redirect_to @log
else
render :action => ‘edit’
end
end
Doing something like @log.changes doesn’t work as @log was just
retrieved from the database and has no changes. params[:log] has all the
new values from the edit form but you can’t do params[:log].changes.
Hope this is making sense, any help appreciated…Bill
I want to send an email when someone changes a field in the record. I
would think I could do this with the ‘update’ method in the controller:
[…]
Doing something like @log.changes doesn’t work as @log was just
retrieved from the database and has no changes.
So don’t do it in the controller. Use a before_update callback instead.
That should give you access to the model object without having to
retrieve it from the DB again.
I want to send an email when someone changes a field in the record. I
would think I could do this with the ‘update’ method in the controller:
[…]
Doing something like @log.changes doesn’t work as @log was just
retrieved from the database and has no changes.
So don’t do it in the controller. Use a before_update callback instead.
That should give you access to the model object without having to
retrieve it from the DB again.