Displaying 20 results from an estimated 500 matches similar to: "after_update: old, new values?"
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 Jun 28
3
how do I validate currency format if I am storing in cents?
Hi all -
To avoid floating point issues, I''ve decided to store monetary values in
cents in the database. However, the user will enter these in dollars
and cents. Two questions:
1) How do I do the validation for the currency format? It looks like
ActiveRecord truncates the cents since it thinks the field type is a
Fixnum. Am I forced to do validation in the controller?
2) Where
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
2006 Jul 06
1
<model>.update(...) not calling before_update callback.
Hi,
I''m doing a <model_name>.update(....) but I''m noticing that my
before_update callback is not being called. If I do a find and then a
save!, I notice that it is called. The problem with a find and save in
my case is that I''m not able to set all my attributes in one shot by
saving params["user"] and since I can''t do this, my overloaded
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
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 Oct 31
2
corrupted index preventing save
Hi, I''m using Rails/AAF with Ferret 0.10.11, and my index occasionally
(every few weeks, roughly) becomes corrupted.
If the index is busted, until I rebuild it our users are unable to save
anything. I get errors like the one below, and the save rolls back.
My question is, is there any way to catch the error, and continue with
the save even if the model isn''t indexed? What
2009 Mar 05
6
About before_* callbacks
Hi
I have an problem about before_* callbacks.
I have a model named: Event
And I don''t want anyone to destroy or update any records in Event
model.
So:
[code]
class ActiveRecord::Base
before_destroy :log_illegal_operations
before_update :log_illegal_operations
private
def log_illegal_operations
Event.create({:key => "illegal operation", :value =>
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
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
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
2010 Sep 22
0
after_update should not be called
Hello,
consider this code: http://pastie.org/1173871
Why after_update in Subscription model gets called?
I''m using Rails 3.
Thanks
--
Posted via http://www.ruby-forum.com/.
--
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
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
2006 Jul 11
8
Stop updated_at from auto updating?
Hi
Is there any way to temporarily stop the updated_at field from being
updated when a record is modified with ActiveRecord?
I have a date field which is keeping track of when the record data was
last checked by my application and my app manually updates it, of course
when I do this the updated_at field is also touched making it fairly
useless for finding out when the actual data was changed
2006 May 08
4
gsub no workie
Don''t know why, but cant seem to get this to work for me.
I have a phone number field for an addressbook. In the addressbook model
I have a before_update declaration that says the following:
I''d like to be able to remove all special characters (just numbers
please), but this doesn''t want to work for me.
before_update :format_phone
def format_phone
self.phone =
2007 Dec 15
2
Reading Model data before update
Hi all,
here is the challenge:
I have this validation method, that basically prevents an object which
billed = true to be updated:
def before_update
if read_attribute(:billed)
errors.add_to_base(''This service has already been billed for'')
end
!read_attribute(:billed)
end
The above code does not work in case I do something like:
object =
2006 Jul 19
6
ActiveRecord::RecordNotSaved - bizarre behaviour.
Hi. I get a RecordNotSaved exception when trying to create a user record.
The error:
User Columns (0.005930) SHOW FIELDS FROM users
SQL (0.000465) BEGIN
SQL (0.000466) COMMIT
ActiveRecord::RecordNotSaved (ActiveRecord::RecordNotSaved):
...
As you can see, there''s no INSERT SQL generated, which is the root cause
of the problem.
In my user model, I have the following
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 May 04
5
Something wierd with .save method
Hi,
I have a very sime app.
I need to create as many records in the db as the selected
checkboxes (named :isselected) in the view.
Here is the code snippet from the controller:
isselectedhash = params[:isselected]
for mod in isselectedhash.keys
@issue = Issue.new(params[:issue])
@issue.state = ''NEW''
@issue.mod_id = isselectedhash[mod] # this gets
2006 Jan 03
2
Stopping a save from the before_save
What''s the better thing to do in a before_save if you don''t want the
save to continue?
raise an exception, or do an errors.add or both?
Thanks,
Chris Nolan.ca
http://kweschun.com/ - Do you have a Kweschun?