Displaying 20 results from an estimated 45 matches for "before_upd".
Did you mean:
before_add
2007 Jan 04
6
after_update attributes problem
...r_item_test.rb:31]:
<-115.5> expected but was
<-113.44>.
3 tests, 6 assertions, 1 failures, 0 errors
So changing the amount on a transaction (RegisterItem) should change
the current balance of an account. Here''s the relevent callbacks:
REGISTER_ITEM UPDATE CALLBACKS:
def before_update
account.balance -= amount
account.save
end
def after_update
account.balance += amount
account.save
end
So the idea is that before the transaction is updated i subtract the
amount of the transaction back from the account, and then add the new
amount back on. It looks like...
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 equa...
2006 Jun 24
0
before_save and before_update not being called in tests
In one of the models I perform some operation. For simplicity let''s assume
that I populate column ''b'' with column ''a'' * 2.
def before_update
self.b = self.a * 2
end
In my fixture I set values for a.
first:
id: 1
a: 10
Whe I run the test before_update is never invoked when rails populate the
test table with the data from fixture. In development mode from the browser
everything works fine.
Any idea why in test the berfo...
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 = self.phone.to_s.gsub(/\D/, "")
end
The following wor...
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 = Model.find(:first)
object.billed = true
object.save
because in my...
2006 Feb 22
3
after_update: old, new values?
With after triggers in Postgres, there are special NEW and OLD vars
accessible to trigger functions. Any such thing in Rails? Or would it
entail doing something like setting a class var in before_update?
Jack
--
Posted via http://www.ruby-forum.com/.
2006 Feb 22
0
How to get model observer to work?
...tive_record.observers = :item_observer
In item_observer.rb I have:
class ItemObserver < ActiveRecord::Observer
observe Item
def after_update(item)
if @old.active != item.active
logger.debug ''observer#after_update''
#...
end
@old = nil
end
def before_update(item)
logger.debug ''observer#before_update''
@old = Item.find(item.id)
end
end
ItemObserver.instance # I''ve tried commenting this out too
Neither the before_update or after_update callbacks appear to be getting
called. How do I make this work?
Thanks,
Jack...
2006 Jun 23
10
Don''t un-admin the last administrator
...moved from
the system.
I need to protect against this both when deleting a user and when
editing a user as you can revoke a user''s administrator privileges via a
form.
User belongs_to :account.
Account has_many :Users
I was thinking that the best way to do this would involve either
before_update and before_destroy or a validation. I think I know how to
write the before_delete as that just involves knowing which user you are
going to delete and checking if its account has more than one
administrator. I am unsure how to write before_update as that requires
not only knowing which use...
2006 Feb 22
5
Auditing mixin for model classes. Small problem
I want to include common auditing functionality in my models. This
involves storing the changes made to a model in a seperate table :
I have created the functions in an Audit module :
module Audit
before_update :before_changes
after_update :after_changes
def before_changes
old=self.class.find(id).attributes
@changes=[]
attributes.each do |key, val|
if val != old[key]
change = Change.new(:primary_key_id=>id,
:table=>self.class.table_name,...
2006 Feb 17
5
getting old values
Hi all,
I''ve add :before_update event to my model
Before updating a record I want to check if new attributes differ to old attr.
My question is how to retrieve old attributes in :before_update event ?
thanks
--
gratis egold 1$ http://shegold.com/
2006 Jun 28
3
how do I validate currency format if I am storing in cents?
...ormat? 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 is the appropriate place to do the conversion from dollars to
cents? I initially was thinking of doing the conversion in
before_create or before_update, but again, it seems like the value is
truncated as described above.
Thanks.
Ken
2007 Sep 07
6
ActiveRecord::Base#update_all expected behaviour
Hi
I noticed that if in my code I use the following:
Photo.update_all("title = ''Ruby rocks'' ", "id IN (#{@photo_ids})")
All my objects are properly updated but none of the filters/callbacks
are triggered. Is that what''s expected?
I have a before_update filter set on the Photo class and it gets
totally ignored, I guess the only way to solve this issue is to
enumerate through the objects and update them one after the other :(
Thanks,
-Matt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscri...
2007 Mar 17
4
Created_on and updated_on in a non-ActiveRecord model
...s that I also want the behaviour of the created_on and
updated_on columns, that get modified automatically before saving.
The problem is that I have my own "save" method and it does not work
(remember this is not a real ActiveRecord model). I''ve tried to set the
before_create and before_updated methods but they does not work (see
code below).
So
is there any way to do it automatically?
Thanks.
*******
[1]
http://wiki.rubyonrails.org/rails/pages/HowToUseValidationsWithoutExtendingActiveRecord
, Alternative 2.
CODE:
class PageMetadata < ActiveRecord::Base
def self.columns()...
2006 Aug 09
1
How to Disable Callbacks on a Model
Does anyone know how to disable a model''s callbacks?
I have a routine that increments a page_view counter for various model
objects in an after_filter in my ApplicationController. I call this:
increment_page_view()
Rather that checking through the trace array in each model callback for
"increment_page_view" I''d rather disable the callbacks from inside
2006 Jul 06
0
updating model bypasses callbacks
Hi,
Very quickly, I''m having trouble calling my before_save ro before_update
callbacks when I do something like User.update(id, params["user"]). I
notice that Rails is calling after_save but for some reason it doesn''t
call the before_save or before_update callbacks. Any thoughts would be
appreciated.
Thanks.
--
Posted via http://www.ruby-forum...
2006 Mar 16
1
sql functions in cru ( not d )
Hi,
I''m looking at ways to encrypt email addresses rather than storing
them directly in the database.
There are several ways that it could be done. I could make an
Encrypter class and use before_update, etc. Or I could set up an
updatable VIEW in mySql. (I guess triggers might be another
possibility.)
However, what I would really LIKE to do is use the handy AES_ENCRYPT
and AES_DECRYPT functions in mySql. If I were doing this with
straight sql, I would just use
INSERT INTO myTable...
2006 Mar 26
5
How to write manage created_on and created_by via mixin?
...ted
self.updated_on = Time.new
self.updated_by = @user.user_id
end
end
And, then I include it and setup the before_create and after_create macros:
require ''lib/UserTimestamp.rb''
class Video < ActiveRecord::Base
include UserTimestamp
before_create :mark_created
before_update :mark_updated
# ... etc...
end
Of course, this doesn''t work, but that seemed logical. Neither @user or user
is present, nor do I have any way to get the user_id. User is identified in
my ApplicationController by a filter which is available in all my
controllers. However, I have absol...
2012 Sep 17
1
require current_password to update user information
...ord_field :password, size: 40 %>
</div>
<div class="field">
<%= f.label :password_confirmation, ''Confirm'' %><br />
<%= f.password_field :password_confirmation, size: 40 %>
</div>
*I''ve tried using a before_update :confirm_password in the User model, but
it hasn''t worked.*
*I created a private method in the user controller*
*
*
private
def password_match
@user = User.find(params[:id])
@user.authenticate(params[:current_password)
end
then call a before_filter :password_match, :only =>...
2006 Mar 13
1
adding custom cache field
...tize.modify_value(\"#{self.to_s.underscore.pluralize + "_total"}\",#{association_primary_key},#{options[:total_cache]})" +
" unless #{association_type}.nil?''"
)
module_eval(
"before_update ''#{association_type}.constantize.modify_value(\"#{self.to_s.underscore.pluralize + "_total"}\",#{association_primary_key},#{options[:total_cache]} - #{self}.find(id).#{options[:total_cache]})" +
" unless #{association_type}.nil?'...
2007 Aug 22
8
How to spec an attachment_fu model
First off, I''m not trying to spec attachment_fu, I know it''s been tested.
But, I added some code to that model that I do need to test. Basically,
I need to somehow fulfill the "uploaded_data" property so I can actually
run my tests(otherwise they fail because of validations). The
"uploaded_data" field is what would grab the multipart data from form.
Here