similar to: calling save in after_create hook

Displaying 20 results from an estimated 4000 matches similar to: "calling save in after_create hook"

2009 Mar 29
2
after_create and after_save
Hi, AFAIK after_create is called after_save if the entry does not exist in the DB. Is there a way to tell if a specific model is new or not in after_save? I have to do something like: def after_save add_to_history ''save'' end def after_create add_to_history ''create'' end However after_save is called when creating too. -- cheers, M.
2010 Oct 01
20
Paperclip not executing FFMPEG properly
Im using a customs processor to run ffmpeg on a video to create a thumbnail. So far so good. Except when I do: cmd = "-i #{@file.path} -f flv -s 320x240 ~/Downloads/foobar/q.flv" success = Paperclip.run(''ffmpeg'', cmd) Console is reporting: ffmpeg ''-i /var/folders/uL/uL0bYOOZEZaJH5E+BmDJVE+++TI/-Tmp-/stream, 16824,1.mpeg -f flv -s 320x240
2007 Dec 13
16
"Tricks" for testing after_create callback???
I''ve got a model Message, which needs to send an email using action mailer after it''s first saved in the database. I want to pass the model to the mailer which then uses methods on the message model to render the email. So the natural way to do this is in an after_create callback on the Message model. But I can''t see an easy way to test this. Here''s my spec
2006 Mar 15
4
help with DRY violation
I''m trying to be a good rails developer and fix DRY violations as i find them. However, i''m trying to fix this one, i cant seem to get it to work. I have two tables A and B that have a one-to-one relationship. Table B belongs_to Table A. Table A has_one Table B. I''m creating instances of Table A in different places, depending on the controller. However, for each
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
2009 May 25
4
after_create and has_one association bug?
Hello, I''ve come across an issue that I''m sure is a bug when using after_create with a has_one association, but I''m not 100% certain if I''m missing something. This is pretty much exactly the code I''m using. Two simple classes (Account and Contact) and I create the contact after I create an account (via after_create). I''m not passing in a
2008 Apr 30
6
best practice for object transaction?
I have a new @offer that needs to generate a document if saved. But that''s all or nothing: transaction do @offer.save! generate_document end # handle exceptions if needed If save! fails everything is fine, but if generate_document raises an exception @offer is left as a model with timestamps, id, which is not a new_record? anymore (though the database was
2008 Apr 25
6
ActionMailer
Hi all, I need a help. I have got a user registration form, where the user signs up and then an activation link is sent to the user email id for activating his/her account. Now I need to send an another email to the user, only after he logs in for the first time in my site, then the second email should be sent. Can anybody give me some suggestion on how to do it ?? NB: When the user clicks on
2006 Aug 17
4
Automatically creating associated records with after_create
Hi all. I am actually using ActiveRecord outside of Rails but I don''t see that it matters for this question. I want to automatically create a registration entry when I add a new user to my application. This works fine, but it''s not automatic: class User < ActiveRecord :: Base has_many :registrations end class Test user = User.new user.registrations.create end
2009 Jul 21
2
Machinist - having problems stubbing an after_create filter
Hi all I''m moving to using Machinist in my rspec tests and am having a problem with an after_create callback method that i need to stub out. It seems like calling ClassName.make will trigger this callback before i''ve had the chance to stub it. Can i stub it in my blueprint for that class? Or, can i stub the method for all instances of the class before i call ClassName.make?
2010 Aug 18
11
When after_save isn't after the save....
I have a Production model, which represents a farmer''s crop. After create (via after_save) I call a method that creates one or more Supply models, which represent a week of anticipated product harvest. After each of those are created, a class method gets called that tries to match each new Supply with outstanding orders for the same time period. If a match is made, a transaction (an
2006 Aug 14
2
after_create is not being called
Hi all I have the following model: class PhotoGallery < ActiveRecord::Base attr_accessible :title, :description, :file_path, :title_photo_id has_many :photos, :dependent => :destroy belongs_to :title_photo, :class_name => ''Photo'', :foreign_key => ''title_photo_id'' validates_presence_of :title, :description, :file_path
2007 Sep 05
2
after_create callback called twice in test env when using fixtures
All, I''ve been trying to figure out a strange bug in one of my applications that I think I''ve narrowed down to a problem with rails fixtures. It seems as though the after_create callback is being run twice when I save a record. This is only happening a) in the test environment, and b) when there is a fixture file for that table. The test below only prints "Doing
2006 May 18
3
ActiveRecord after save new and old values
I want to write a function that after an ActiveRecord saves successfully, can show me what the before and after values of a particular column are. Is this possible without creating a separate object before modifying the current one? -John
2008 Jun 03
1
after_create callback in subclass
I have a User model with a protected method defined: def set_role(rolename) role = Role.find_by_rolename(rolename) permission = Permission.new permission.role = role permission.user = self permission.save(false) end and a subclass with: after_create set_role(''client'') This always fails for me with the error: undefined method `set_role''
2006 Aug 15
1
Update attribute without validations or any save hooks?
If I wanted to update an attribute with calling any validation or any of the before_save and after_save hooks, how would I go about doing this? Supposed the update_attribute method calls the before and after save methods. Thanks for your help. -- Posted via http://www.ruby-forum.com/.
2006 Jul 05
2
Serialized object behaves weird
Hi! I got a class named EinsatzFilter which I serialized to session. Before saving to session it works afterwards I keep getting the message: "undefined method `to_s'' for #<Person:0x38c6ab8>". "Person" is a from ActiveRecord::Base inherited class. Code: class EinsatzFilter include ApplicationHelper attr_reader :personen, :monat, :projekte, :kunde
2012 Nov 10
6
Suggestion: `before_save on: :create` should either work or raise an exception
There''s a small inconsistency in ActiveRecord''s callback syntax that has tripped me up before. It wouldn''t be a big deal, but it can lead to a silent failure. I''d like to suggest that it either be made consistent or be made to fail loudly. The issue is that to do something before validating, but only when creating, you use `before_validation on: :create`,
2006 Jul 17
5
Keeping attributes of two models in sync
Hi, I have a Product and a corresponding Keyword (1:1 via belongs_to and has_one). I want to ensure, that two attributes (:name) of the two models alway stay in sync. What''s the easiest way to accomplish that? I did play around with before_/after_save hooks and with AR::Observers but in the end I''d always get infinite recursion... Thanks, Timo
2008 Mar 11
6
saving an ActiveRecord without trigging the callbacks
Hello, How can I save an ActiveRecord without trigger before_save, after_save, etc? Thanks for the help. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group,