Displaying 20 results from an estimated 200 matches similar to: "after_destroy callback order in Rails3.1.3"
2006 Jan 05
2
ActiveRecord callbacks not happening
Hi,
I have a model class like so:
class Candidate < ActiveRecord::Base
validates_presence_of :name
@@index = FerretConfig::INDEX
def self.after_destroy
puts "Ferret: after_destroy called"
@@index.query_delete("+id:#{self.id} +ferret_class:#{self.class.name}")
optimize_index
end
end
But when I delete a record, the after_destroy is never called.
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
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,
2009 Sep 27
1
Switchboard - Easy to use global ActiveRecord event listeners
Switchboard is a simple, event-observing framework for ActiveRecord.
It''s designed to make it easy to add observers for all models in your
app, and to easily turn them on and off selectively.
Intallation
gem sources -a http://gems.github.com
sudo gem install zilkey-switchboard
Usage
First, require switchboard above your rails initializer:
# environment.rb
require
2006 Apr 26
3
acts_as_taggable gem: deleting tags
I have the following quick-and-dirty hack in my model:
def after_destroy
# search for orphaned tags and delete them
orphans = Resource.tags_count :count => ''= 0''
orphans.keys.each {|tag| Tags.find_by_name(''tag'').destroy}
end
It''s nice from a readable code perspective, but it seems inefficient -
is there some way to do this with only one
2010 Mar 28
1
keeping track of who did what
hello everybody.
i need to log "who did what" on some models. i was reading recipe 59
of rails recipes and i created something like that:
class LogSweeper < ActionController::Caching::Sweeper
observe :model1, :model2, :model3, :model4, :model5, ...
after_save(model)
save_log(model, "save")
end
after_destroy(model)
save_log(model, "destroy)
end
2005 Dec 02
1
cFerret ETA?
I''m noticing some long delays when optimizing my index. I know this
is terribly inefficient, but in order to make sure that my
ActiveRecord model is in sync with my index, I''m optimizing after
every new record that I store, like so:
class Resume < ActiveRecord::Base
include Ferret
has_and_belongs_to_many :users
SEARCH_INDEX = File.dirname(__FILE__) +
2008 Apr 01
1
"Undefined method merge" when using sweeper
Hi,
I''m trying to use sweepers for the first time and got a problem - I
get "undefined method `merge'' for "/signature/
f2d7c7c66450b169.html":String". The "/signature/f2d7c7c66450b169.html"
part of the error message is the cached page.
Here''s my sweeper:
class FooSweeper < ActionController::Caching::Sweeper
observe Foo
def
2008 Dec 05
1
Question About Rails.cache and find method.
The DB load on my site is getting really high so it is time for me to
cache common queries that are being called 1000s of times an hour
where the results are not changing.
So for instance on my city model I do the following:
def self.fetch(id)
Rails.cache.fetch("city_#{id}") { City.find(id) }
end
def after_save; Rails.cache.delete("city_#{self.id}"); end;
def
2005 Dec 08
2
Confusing lock problem in rails
I have a model class in rails that has a class variable that is a
ferret index. For some reason, the methods in my class that refer to
the class variable are getting lock conflicts. Can anybody see any
obvious reason why? I notice that it keeps leaving a lock file in the
index directory. I thought auto_flush was supposed to remove the lock
automatically after every operation. Is there
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)
2008 May 18
0
Spec a before_destroy callback in Sequel
Hi
I''m struggling to find a neat way to spec this. The Sequel ORM
doesn''t support automatically destroying dependent models. It''s easy
enough to do in a callback though:
class Changeset < Sequel::Model
has_many :migrations, :class => DataModel::Migration
before_destroy do
migrations.each { |m| m.destroy }
end
# ...
end
2006 Jan 25
1
cache_sweeper causes undefined method error
I created a sweeper ItemSweeper and saved it in
app/models/item_sweeper.rb. Then I put this in my item_controller.rb:
cache_sweeper :item_sweeper, :only => [:create, :destroy, :update]
But now when I call the view action, I get this error:
ActionView::TemplateError (undefined method `title'' for nil:NilClass) on
line #5 of app/views/item/view.rhtml:
5: <H1
2009 Jul 02
1
Why do CacheSweepers listen to the Controller
I must be missing something, but it seems that it would be best to have
the sweeper listen to ActiveRecord, and have it expire caches on
after_save & after_destroy.
--
Posted via http://www.ruby-forum.com/.
2007 Oct 24
0
Sweeper for few models
For example - i have a sweeper for one model(in this case About).
class AboutSweeper < ActionController::Caching::Sweeper
observe About
def after_create(data)
expire_about(data)
end
def after_save(data)
expire_about(data)
end
def after_destroy(data)
expire_about(data)
end
def expire_about(data)
FileUtils.rm_rf
2009 Aug 04
0
Authlogic::How to access current user from within a cache sweeper?
So I''m trying to follow along in Chad Fowler''s Rails Recipes (recipe
#59, Keeping track of who did what) and I simply want to access the
current user from within my cache sweeper. Normally you just
reference @current_user but that doesn''t seem to be the case here.
In Chad''s example, he calls controller.session[:user]. What''s the
Authlogic equivalent?
2006 May 24
1
Observer behavior differences between DEV and TEST environments ?
Hi all !
I''m having an issue and I can''t seem to make heads or tails of it.
I am attempting to add an observer to a model object. I created
app/models/greenback_transaction_observer.rb, inherited from
AR::Observer, defined methods, registered in config/environment.rb,
but things don''t work...
So, I took a step back and put in the following code:
class
2007 Sep 10
2
expire_page not working
I''ve enabled page caching on a site I''m currently constructing. The
sweeper is called upon any changes made to the model, as expected.
The sweeper code is as follows:
class PersonSweeper < ActionController::Caching::Sweeper
observe Person
def after_update(person)
expire_staff_page
end
def after_destroy(person)
expire_staff_page
end
def
2006 Apr 24
0
ImageMagick and EXIF Data
Hi there,
I''m writing a little application that parses an image file and extracts the
camera settings from the file (the EXIF data) and saves all the fields to
the database. The idea is that after awhile people will be able to search
based on camera make, model, lens settings, etc... and all the pictures that
meet those requirements will be displayed. The picture is stored on the file
2006 Jul 15
12
Safe way to destroy records
Hello,
how can I check if a destroy was successful?
Is the object only frozen if deleted or do I have to do an additional
find to see if there is a record left?
What happens if an after_destroy callback returns false? Is there always
a rollback?
Markus