similar to: in after_update, possible to see previous value of record?

Displaying 20 results from an estimated 10000 matches similar to: "in after_update, possible to see previous value of record?"

2007 Sep 21
1
Temporary disabling after_update
Hi, I am trying to replace my old database trigger with ActiveRecord callbacks in rails. I have a model like following: class Action < ActiveRecord::Base belongs_to :inquiry def after_update #clean up all action associated with the inquiry. Action.update_all("latest = ''''", ["inquiry_id = ?", self.inquiry_id]) #find the latest action
2007 Jan 04
6
after_update attributes problem
Hey guys, I''m having a hard time w/ the after_update callback on rails... As far as I can tell, when I define a after_update callback on a model, the attributes of the object have the same values that they had *before* Base.save was called. I''m probably wrong so here''s the code: UNIT TEST: def test_register_item_adjusts_account_balance account =
2007 Feb 09
1
after_update and increment!
I''ve got a strange behaviour that didn''t seem to be happening before I upgraded to 1.2. I''ve got two models - questions and results. When a user answers a question, his answer is recorded in results. In my results model, I have an after_create that increments! a count in the question model. This increment is now triggering an after_update method I have in a
2006 Feb 22
5
Auditing mixin for model classes. Small problem
I want to include common auditing functionality in my models. This involves storing the changes made to a model in a seperate table : I have created the functions in an Audit module : module Audit before_update :before_changes after_update :after_changes def before_changes old=self.class.find(id).attributes @changes=[] attributes.each do |key, val| if val != old[key]
2006 Feb 22
3
after_update: old, new values?
With after triggers in Postgres, there are special NEW and OLD vars accessible to trigger functions. Any such thing in Rails? Or would it entail doing something like setting a class var in before_update? Jack -- Posted via http://www.ruby-forum.com/.
2006 Jan 16
2
recording updates
I''ve been searching around trying to find out if there is some way to attach something to an ActiveRecord class such that every time an update is called, a record of that update (which fields, when) is created. I think it would be useful for syncing information with external services I think. Questions: If there is a wealth of knowledge on this, what search terms will lead me in the
2007 Dec 03
2
attachment_fu 'replace' method?
Is there a ''replace'' method or similar for attchment_fu? For instance, I have an image that is uploaded and stored. Now I want to replace it with a different image. I do not want to do a delete and then new - since I need to keep various attributes associated with the previous image. thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message
2006 Feb 27
2
Multiple Undo History
I need to implement multiple undo functionality into a Rails app (my first one). Essentially, every .update and .save needs to record the previous data set and save them in a history table along with some identifying stamps, so each db action can be rolled back at any time. From what i can tell, i could implement this manually using observers perhaps; but this is Rails, so i wonder if
2006 Jul 19
0
save without after_save, after_create, after_update?
How to update attribute(s) and save a record instance without triggering the hooks: after_save, after_create, after_update? I know it''s possible with Record.update() but this is dynamic. Only receive the instance, without knowing its class (thus cannot call the class method update()). Or is there a way of knowing the class and calling the class method? Thank you. -- Posted via
2010 Sep 22
0
after_update should not be called
Hello, consider this code: http://pastie.org/1173871 Why after_update in Subscription model gets called? I''m using Rails 3. Thanks -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to
2006 May 19
5
How to determine if an object has just been created
Is there a built-in way to determine if a model object has just been created (ie. this object was the one that was originally persisted)? I can''t see it anywhere in the AR code, but thought I''d check. I want something like: p = Person.create p.original_instance? # true Is this built-in or should I just patch AR? -Jonathan.
2012 Dec 06
2
Bye Bye, Observers
Observers will be no more as of Rails 4, farewell, never been much of a fan. However, I''m using it in one of my gems which enables model attributes for use with a WYSIWYM editor. The resulting markup is persisted, but in order to use it in a view, it has to be nokogiried in a helper which fragment caches the result. This cache has to be zapped once the model instance is either
2009 Jun 27
1
Problem with :touch in belongs_to
I''ve read in rails api that there is a touch parameter and I want to use it in my application. I have something like that class User < ActiveRecord::Base has_many :phones after_update :updated def updated ... end end class Phone < ActiveRecord::Base belongs_to :user, :touch => true end I want that every change of any phone number would change User updated_at
2006 Apr 06
7
LoginSystem : make @session available to models
Hello. LoginSystem is cool, it populates the @session instance variable of controllers with many useful info. The fact is : it would be cool to let models know about the session, too. For instance, after_update and after_create callbacks could store *who* did *what* on *what. Aim : having ActiveRecord::Base::session defined, returning the @session of the controller which manipulates the
2007 Apr 05
2
best way to maintain dynamic fields?
I have a Topic that has_many comments. In the search results only want Topics to show up, but I want them to include the text of the comments that they have when they are indexed. To do this I''ve added a :comments_text field for acts_as_ferret and the comments_text method gathers the text from all comments up into a string that can be indexed. The trick is that when comments are added,
2006 Sep 15
2
Caching::Sweeper Access to Controller
Hello, I''m running Mongrel 0.3.13.3, cluster 0.2.0, and Rails 1.1.6 and I have a problem with a sweeper not having access to the controller instance. NoMethodError (undefined method `session'' for nil:NilClass): /app/models/audit_sweeper.rb:16:in `log'' /app/models/audit_sweeper.rb:9:in `after_update''
2007 Feb 14
4
cache sweeper not getting called
Hi, I''ve started to implement page caches but I''ve hit a brick wall getting a sweeper to clear the cache when needed. It seems that any models that I tell it to observe aren''t being observed properly. If I add the sweeper to a controller the initialize method runs, but no matter what I do the after_save/after_update callbacks aren''t running. Also if I try to
2007 Sep 07
3
Fails to restart mongrel cluster after Capistrano rollback (PIDs not deleted)
Hi, I am deploying a Rails website using Capistrano to a VPS running the site through Apache and Mongrel. ''cap deploy'' works fine, and mongrels are restarted. When I execute ''cap deploy:rollback'', however, my script fails to restart the mongrels giving this error: !!! PID file tmp/pids/mongrel.5000.pid already exists. Mongrel could be running already.
2006 Oct 25
4
Search result inconsistencies due to indexing
I seem to be having problems with getting my searcher to be consistent while indexing. I am running the latest version of ferret (0.10.13) and I am using the Searchable plugin. Currently the way it indexes is by using a callback in the model of either after_update or after_create to index the fields that I have setup to be indexed. Right now I update the index about once every 4 or 5
2006 Apr 13
2
acts_as_versioned gem
I''ve installed the acts_as_versioned gem, and it shows up as installed when i do a "gem list" After installing it, I set up my new model with the "acts_as_versioned" line in its model file. I think went to run my migration to create this table, and I got the following error: == CreateDpslevels: migrating ================================================ --