search for: after_update

Displaying 20 results from an estimated 59 matches for "after_update".

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 latest_action = Action.find(:first, :conditions => ["deleted <> 1 and inquiry_id = ?&qu...
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_...
2007 Mar 09
1
in after_update, possible to see previous value of record?
I have this situation where in an after_update, I would like to know the previous value of the record instead of simply being notified the record has been updated. For example let''s say I had a table called ''foo'' which had a field ''new_flag''. I want to know when the ''new_flag'' fie...
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/.
2007 Feb 09
1
after_update and increment!
...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 question_sweeper. (which causes an error) This sweeper is used to sweep my question cache files. I started noticing this problem when I went into production mode. Development mode pre-1.2 was working fine. Production mode pre-1.2 was not. I upgraded to 1.2 today because I though...
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 http://www.ruby-forum.com/...
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 rubyonrails-talk-/JYPxA39Uh5TL...
2012 Dec 06
2
Bye Bye, Observers
...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 updated or destroyed. An observer for after_update and after_destroy seemed the obvious choice at that time. What would be a Rails 4 approach for this without observers? Inject after_update and after_destroy callbacks directly into the model? -sven -- You received this message because you are subscribed to the Google Groups "Ruby on Rai...
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 model. Here''s a way to do that. I was wondering whether it was good ruby and good rails because I''...
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 and also call user after_update callback. But when I add :touch parameter I get error that looks like...
2006 Feb 22
0
How to get model observer to work?
I can''t seem to get a model observer to work. In my environment.rb I have: config.active_record.observers = :item_observer In item_observer.rb I have: class ItemObserver < ActiveRecord::Observer observe Item def after_update(item) if @old.active != item.active logger.debug ''observer#after_update'' #... end @old = nil end def before_update(item) logger.debug ''observer#before_update'' @old = Item.find(item.id) end end ItemObserver.instance # I'...
2007 Oct 22
5
How to hook into model attribute changes?
Hi, What''s the best way to hook into any changes made to the value of a single model attribute? I need to know when the encrypted_password attribute on my User model changes i.e. when the user has changed their password. I''m not interested in the actual changed value, I just need to know when it''s been changed so that I can regenerate their API key as well. Thanks in
2007 Apr 05
2
best way to maintain dynamic fields?
...''ve included my current code to do this, which seems to work, but I''d like to know if there is a better way to maintain this dependency then what I''m doing. In particular am I using appropriate callback methods in Comment to trigger the updates on Topic (ie. after_create, after_update, after_destroy). And to make the destroy case work I''m needing to call unless each.frozen? in the comments_text method... is that the right thing to do? Thanks. Here''s my existing code: class Topic < ActiveRecord::Base acts_as_ferret :store_class_name => true, :fields =&...
2006 Sep 15
2
Caching::Sweeper Access to Controller
...ongrel 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'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/ active_record/observer.rb:123:in `send'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/ active_record/observer.rb:123:in `update'' /usr/lib/ruby/1.8/observer.rb:185:in `notify_observers''...
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 minutes. The problem occurs when I do a search and either no results ( or a very small amount like 2) are returned for particular keywords that previously had plenty of re...
2007 Feb 14
4
cache sweeper not getting called
...lement 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 call "expire_page", I get a method missing error. It seems like the class isn''t actually extending the Sweeper at all, is there something I''m missing?? Here''s the sweeper code: class PublishSweeper < Acti...
2007 Sep 07
3
Fails to restart mongrel cluster after Capistrano rollback (PIDs not deleted)
...ngrels giving this error: !!! PID file tmp/pids/mongrel.5000.pid already exists. Mongrel could be running already. Check your log/mongrel.5000.log for errors. I have a hunch that the error is related to the fact that I link /tmp/ pids into the shared directory upon each release in the "after_update" task, but I''m not sure how I end up with this problem, as the old dir I''m rolling back also has the link setup. The mongrels are stopped, but for some reason they don''t clean up their PID files, and thus they fail to start again. The full output of the rollba...
2006 Jun 01
0
question about observer callbacks
I''m not sure how to implement this so I''ll describe what I currently have done then what I wish to have happen currently, I have a generic observer for several models class AuditObserver < ActiveRecord::Observer observe Foo, Bar def after_update(model) model.log("UPDATED " + Time.now.strftime("%m-%d-%Y %H:%M")) end def after_create(model) model.log("CREATED " + Time.now.strftime("%m-%d-%Y %H:%M")) end def after_destroy(model) model.log("DESTROYED " + Time.now.strftime(...
2006 May 31
0
restrict callback to fields
please can some kind soul point me to the right track. how can I express: "do something when any field of this class is updated except field X" I need to do anything that would behave like after_update :do_something #unless the updated field is field X that is: after_update is called every time a set_ method is called, except set_x Is that at all possible? Isabelle -- Posted via http://www.ruby-forum.com/.
2006 Mar 30
0
Specify callbacks before associations
...ecifying the associations. Otherwise, you might trigger the loading of a child before the parent has registered the callbacks and they won?t be inherited." Does this mean a model should be defined as: class NetworkSegment < ActiveRecord::Base after_create :create_network_ipaddresses after_update :update_network_ipaddresses has_many :network_ipaddresses, :order => octet4 #... end or class NetworkSegment < ActiveRecord::Base has_many :network_ipaddresses, :order => octet4 after_create :create_network_ipaddresses after_update :update_network_ipaddresses #... end Th...