Displaying 20 results from an estimated 300000 matches similar to: "does after_save get called if failed save?"
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 28
1
:has_many and :after_save
Having one to many connection (for example post has many comments), what
is the most efficient way of saving all comments when post is saved.
Using after_save on Post would introduce the n+1 problem. Is there any
way of saving the whole structure at once?
--
Posted via http://www.ruby-forum.com/.
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 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
2008 Jul 28
1
callback executed like after_save but after transaction
I''m trying to add some code for my ActiveRecord class so that it is
executed whenever an object is updated, this code is a seperate
process that reads from the same table represented by my model class
so when it runs it needs the database to be up to date.
In the following situation this is fine:
# MyModel
def after_save
`/usr/local/bin/update_models -i #{self.id}`
end
# controller
2012 Jan 28
2
after_save in plugin
Dear list,
I am trying to override an after_save callback declared in main app
using plugin.
The main model class is:
class WorkHours < ActiveRecord::Base
@after_save_call_back_called=0
after_save :after_save_call_back
def after_save_call_back
logger.debug "after save called"
@after_save_call_back_called=1
end
end
And in my plugin (in the lib directory) :
module
2006 Nov 19
1
ActiveRecord save-update not performed ?
I try to understand the following issue :
- when creating a new User record, I use an UserObserver to trap the
before_save call back and send an email
def after_create(user)
UserNotifier.deliver_signup_notification(user)
end
- Once created a user can ask for a password reset, which is also
trapped by the UserOberver
def after_save(user)
UserNotifier.deliver_reset_password(user) if
2006 Apr 01
2
ActiveRecord callbacks not called
Hi, there must be something wrong somewhere in my unit test because
there''s a model I can''t have any callback executed on.
In my unit test I do
@image = Image.new
@image.set_uploaded_file({:file =>
uploaded_file("pic1.jpg","image/jpeg","article-picture.jpg"),
:article_id => @article.id,
:title => ''Titre
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/.
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
2006 Aug 17
3
How to save output "render :action=>:any_action" to a file?
I need to save the output of my rails app to a file. i.e. instead of
rendering a page when using "render :action=>:any_action" i want the
output to be saved to a file.
Anyone got any ideas?
Thanks
Chris
--
Posted via http://www.ruby-forum.com/.
2006 Jul 17
2
Very strange after_save problem. Please help.
I have a very strange problem here. I do not get this. So any help is
greatly appreciated.
Basically I have a model that calls a method in the background
process in the "after_save" method. Let''s call the model products. So
what happens is this:
1. I create a new product.
2. Everything works and the product is saved with id 13.
3. A method is called in my background
2010 May 12
2
How to add an after_save callback on runtime on a particular instance
class User < AR
end
user = User.new
Let''s say that I have a user instance with me. After this record is
saved I want an after_save callback which would print the id of the
record.
The only catch is that I am not allowed to change the User class. How
can I accomplish my goal? Is that even possible to add an after_save
callback on a particular instance object. Any metaprogramming
2007 Feb 05
0
after_save and associations
It appears that when after_save is triggered, associations such as
habtm haven''t been populated yet.
Each association can have an :after_add callback, but my code needs to
access multiple associations.
Is there an explicit reason why after_save isn''t triggered after all
of the associations have been populated?
--~--~---------~--~----~------------~-------~--~----~
You received
2006 Jul 17
2
after_save deletes is an exception is raised?
Does after_save in a model delete if an exception is raised in there?
I simply did
def after_save
raise ''hmmm''
end
and it raised the exception but there was nothing in the database. I
removed that entire method and its in the database. Is this correct?
Thank You,
Ben Johnson
E: bjohnson@contuitive.com
-------------- next part --------------
An HTML attachment was
2010 Aug 08
2
paperclip save to disk and s3
I have a standard Paperclip setup that saves a file to my disk. In
addition I would also like the file saved to my amazon s3 bucket.
[code]
after_save :copy_to_s3
def copy_to_s3
has_attached_file :photo,
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:styles => {
:thumb => "100x100#",
:small => "750x750>"
2008 Nov 13
3
Creating a file and saving in public directory
Hello,
I''m fairly new to Ruby on Rails.
I have a model called Report and I''m trying to create a text file that
is saved in a /public/report directory.
I''ve had a look at the ruby api but I can''t seem to get this working.
The current code I have is:
#report.rb
class Report < ActiveRecord::Base
after_save :write_file
def write_file
if @file_data
2009 Jan 18
2
after_save -- stack level too deep
Hi all,
I''m running into a brick wall trying to figure out my problem here. I
have a model that has a boolean property called "paid". I''d like to
add the following to my model:
def after_save
self.amount == self.splits.sum(:amount) ? self.update_attribute
(:paid, true) : self.update_attribute(:paid, false)
end
The problem is, when I do this I get an error that
2006 Jun 01
0
Disabling an after_save() in a rake conversion?
Hi all -
I''ve got a model Foo that has an after_save() method. I''d like to disable
it while doing a rake conversion.
Seems I should be able to just redeclare Foo.after_save() somehow, but I''m
not quite sure how to do that in the rake task...
Any ideas?
Thanks!
-philip
2008 Dec 13
3
session In the model
Hi
i have the model SDTicket which has a field modified_by_id and it has
to take data from session[:id] Now this SDTicket model has many
associated models like Activity one of them So when ever an activity
happens then also the value in session[:id] is to be go to
modified_by_id field
SDTicket has_many activities
Activity belongs to SDTicket
So for that what I am trying is in Activity