search for: after_destroy

Displaying 20 results from an estimated 45 matches for "after_destroy".

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. Nothing shown on logs from the puts statement. Am I missing something...
2012 Jan 24
0
after_destroy callback order in Rails3.1.3
...se and Rails 3.1.3 and ruby 1.9.3 I have 3 models. - Activity - ActivityObject - ActivityObjectActivity They are related this way. **Activity** > has_many :activity_object_activities,:dependent => :destroy > has_many :activity_objects, :through => :activity_object_activities > after_destroy :do_something_on_activity_object_related **ActivityObject** > has_many :activity_object_activities, :dependent => :destroy > has_many :activities, :through => :activity_object_activities **ActivityObjectActivity** > belongs_to :activity, :dependent => :destroy > belongs_t...
2012 Dec 06
2
Bye Bye, Observers
...ributes 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 Rails: Talk" grou...
2006 Mar 13
6
:dependent => :destroy
Hi, There is something I don''t understand about :dependent => :destroy. I hope someone can help me. Consider this code: class Folder < ActiveRecord::Base has_many :myfiles has_many :folders has_many :group_folders, :dependent => :destroy validates_uniqueness_of :name, :scope => "folder_id" validates_presence_of :name before_destroy
2007 Apr 05
2
best way to maintain dynamic fields?
...ncluded 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 => { :co...
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 w...
2006 Jan 31
2
Fragment caching and pagination
I''m just getting my hands dirty with caching. The pages I want to cache have some user specific data on them (for example "log out"). That sent me down the route of fragment caching. One of the things I want to pagination is a paginated list. My question is how is pagination and query strings handled with fragment caching? Does each page get its own fragment and query string
2010 Mar 28
1
keeping track of who did what
...uot;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 private save_log(model, event, user_id = controller.session[:account_id]) #create the log entry, i want to save the id of the model, the id of the logged user and something to describe the action. #controller isn''t defined here...
2005 Dec 02
1
cFerret ETA?
...# syncronization with ferret index def after_save @@index ||= Index::Index.new(:path => SEARCH_INDEX, :create_if_missing => true) @@index << {:id => id, :email => email, :contents => contents, :date => found_on} @@index.flush @@index.optimize end def after_destroy @@index ||= Index::Index.new(:path => SEARCH_INDEX, :create_if_missing => true) @@index.delete(id) @@index.flush @@index.optimize end ... end I''m noticing about a 2-3 second delay after every new record that I store. I''m thinking that this will be bearab...
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
2009 Sep 27
1
Switchboard - Easy to use global ActiveRecord event listeners
...39;' Rails::Initializer.run do |config| # ... end Add the listeners to the Switchboard in an initializer: # config/initializers/switchboard.rb Switchboard.listeners << ActivityFeedListener Then, create a listener class that defines methods for after_create, after_update and after_destroy: class ActivityFeedListener class << self def after_create(record) description = "#{record.class.name} was created" publish_activity_feed_items record, description end def after_update(record) description = "#{record.class.name} was updated&quo...
2008 Apr 01
1
"Undefined method merge" when using sweeper
...ure/ 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 after_save(foo) expire_cache(foo) end def after_destroy(foo) expire_cache(foo) end def expire_cache(foo) expire_page signature_path(:opaque_id => foo.opaque_id) # line 13 expire_page signature_image_path(:opaque_id => foo.opaque_id) end end The signature_path(:opaque_id => string) generates "/signature/ string.html&quo...
2008 Dec 05
1
Question About Rails.cache and find method.
...es 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 after_destroy; Rails.cache.delete("city_#{self.id}"); end; So now when I can City.find(1) the first time I hit the DB but the next 1000 times I get the result from memory. Great. But most of the calls to city are not City.find(1) but @user.city.name where Rails does not use the fetch but queries th...
2005 Dec 08
2
Confusing lock problem in rails
...if_missing => true, :auto_flush => true, :close_dir => true) # syncronization with ferret index def after_save @@index << {:id => id, :email => email, :contents => contents, :date => found_on} end def after_destroy @@index.delete(id) end def self.optimize_index @@index.optimize end def self.search(query, options) docs = [] count = @@index.search_each(query, options) do |id, score| doc = {} doc[:id] = id doc[:email] = @@index[id][''email''] doc[...
2011 Jul 22
9
Active Record Issue (I think)
I''m following a rails tutorial (Hartl) and it''s been fine so far, but something doesn''t seem to be working right. I have two basic models so far, "User" and "Micropost". class User < ActiveRecord::Base has_many :microposts end class Micropost < ActiveRecord::Base belongs_to :user end If I do something like: "first_user =
2005 Dec 15
8
How to ensure deletes cascade to associated models?
I have the following models: class Resume belongs_to :resume_assignments end class User belongs_to :resume_assignments end class ResumeAssignment has_one :resume has_one :user end When I delete a resume, I want to make sure that its associated ResumeAssignment gets deleted also. Calling destroy_all to delete some resumes doesn''t seem to do this. Is there an option that will
2007 Sep 13
5
refreshing indexes?
I am new to ferret and am just reading about it in the O''reilly shortcuts as well as other web resources. My app is a Rails app and so I am looking into acts_as_ferret as well. There are some questions for which I couldn''t find answers in the material I have read so far so I''d appreciate any help on these from the list. A bit of a background. My app will have 10,000 -
2005 Dec 02
1
Compile error on FreeBSD 4.10 gcc 2.95.4
...dex.new(:path => SEARCH_INDEX, > > :create_if_missing => true) > > @@index << {:id => id, :email => email, :contents => contents, > > :date => found_on} > > @@index.flush > > @@index.optimize > > end > > > > def after_destroy > > @@index ||= Index::Index.new(:path => SEARCH_INDEX, > > :create_if_missing => true) > > @@index.delete(id) > > @@index.flush > > @@index.optimize > > end > > > > ... > > end > > > > I''m noticing a...
2006 Jun 20
2
Problem with "can''t dump anonymous class Class"
...lf.file_path)) Dir.mkdir(File.dirname(self.file_path)) end if @uploaded_file.instance_of?(Tempfile) FileUtils.copy(@uploaded_file.local_path, self.file_path) else File.open(self.file_path, "wb") { |f| f.write(@uploaded_file.read) } end end def after_destroy if File.exists?(self.file_path) File.delete(self.file_path) end end def file=(uploaded_file) @uploaded_file = uploaded_file self.file_path = sanitize_filename(@uploaded_file.original_filename) self.content_type = @uploaded_file.content_type end private def...
2010 Jul 11
10
dependent support for has_many through?
...er < ActiveRecord::Base has_many :assignments has_many :projects, :through => :assignments end if I call Programmer#projects.clear, it will delete_all the joining assignments; however, I have a situation where I''d like the assignments to get destroyed instead so that their after_destroy callbacks get called. It would be simple to implement (just call destroy_all rather than delete_all), it''s just not quite clear how the option should be set; since :dependent currently gets ignored when using :through, the seems a logical place, although it''s not quite i...