Displaying 20 results from an estimated 30000 matches similar to: "save without after_save, after_create, after_update?"
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.
2007 Feb 09
1
after_update and increment!
I''ve got a strange behaviour that didn''t 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
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 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
2008 Sep 23
3
calling save in after_create hook
Scenario:
I''m creating an image file upload service for my web site.
As well as saving the actual file I also need to create a database
record for the file.
I would like to name the file after the record id, but I also need to
save some attributes of the image (width/height/mime_type etc) which I
can''t discover until after the file is created.
The Problem:
1) The id is not
2006 Jul 19
1
Catch 22 with after_save. Please help.
I have a pretty strange problem. Here is basically what I have to
demonstrate my problem:
class Event < ActiveRecord::Base
def after_create
AnotherClass.find_event(id)
end
end
class AnotherClass < ActiveRecord::Base
def self.find_event(event_id)
e = Event.find event_id
end
end
Here is the catch 22 and it''s quite annoying. Basically ActiveRecord
puts to whole save
2008 Jul 21
1
Re: Observer
eh, like so?
def after_create(model)
generate_hotel_param_files(model.id)
generate_hotel_setup_files(model.id)
end
def after_update(model)
generate_hotel_param_files(model.id)
generate_hotel_setup_files(model.id)
end
On Jul 21, 9:59 am, David Nguyen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
> Hi,
> I have to make an observer if a
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_balance
account =
2006 Mar 21
0
does after_save get called if failed save?
does after_save get called if failed save?
Thanks,
Chris
--
Posted via http://www.ruby-forum.com/.
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,
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
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'' field changes from 0 --
> 1 in an after_update so I
2006 Mar 30
0
Specify callbacks before associations
In the RoR API documentation
(http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html) for
callbacks, there is a note that says:
"*IMPORTANT:* In order for inheritance to work for the callback queues,
you must specify the callbacks before specifying the associations.
Otherwise, you might trigger the loading of a child before the parent
has registered the callbacks and they won?t
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/.
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 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
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
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
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
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