search for: before_updated

Displaying 20 results from an estimated 45 matches for "before_updated".

Did you mean: before_update
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 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
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
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 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?
I can''t seem to get a model observer to work. In my environment.rb I have: config.active_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
2006 Jun 23
10
Don''t un-admin the last administrator
I have a User class with a field called admin which is a boolean that determines if the user is or is not an administrator. I want to make it impossible for the last administrator for an account to be removed 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
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]
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?
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 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
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() @col...
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.com/.
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
2006 Mar 26
5
How to write manage created_on and created_by via mixin?
Hi! Definite newbie here - I''m working through this like-hate relationship with Ruby and Rails right now... sometimes things work really well (like blobs seem to rock) but other times, I dunno! :-) Anyway, I''d like put in create and update user timestamps on all my primary domain tables and allow them to be updated automatically by ActiveRecord. Coming from Hibernate, I just
2012 Sep 17
1
require current_password to update user information
Rails newbie here, I have been stuck on this for two days and can''t figure out why its not working. I want users to confirm/verify themselves by entering their current/old password before any information is updated. This is what My user_controller update action looks like I''m currently using rails 3.2 with the basic has_secured_password authentication that comes with it. def
2006 Mar 13
1
adding custom cache field
Hello, I needed to add custom cache field for one of my application. I thought I will share the code showing how to do this. This code below creates and maintain a custom cache field, for keeping track of totals. Say, you have accounts, and for each account there are transactions (either deposit/withdrawal), and one will like to keep track of the total balance for an account. So, let there be a
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