similar to: Stopping a save from the before_save

Displaying 20 results from an estimated 1000 matches similar to: "Stopping a save from the before_save"

2006 Jan 03
4
validates_presence_of *_id attributes
Hi all, I am a newbie to Rails. Please enlighten me on how to do this appropriately, the Rails and the Ruby way: Suppose I have a Recipe model. Let''s simplify things and pretend that it has only 2 attributes, a :name and the other is a ''category_id''. In the recipes table, category_id is a foreign key to field id of table categories. We also assume that I have generate
2006 Aug 01
8
Decoupled observers for controllers?
In the Rails Recipes book the recipe "Keeping track of who did what" explains how to do decoupled observing of models. In my application I''d like to do a similar thing but watching the controllers. For example, when somebody hits the login method of the Security controller, I''d like to make a note of it. In this case I could observe the User model and watch for
2005 Dec 30
2
Crashing Firefox when updating the same div
I''ve managed to consistently crash firefox 1.5 (mac) using script.aculo.us. Is this a known issue? The page in question works in Safari enough. It happens on a link_to_remote where I''m :updating the same div that I''m currently in. Would it help if I try to isolate the code? Would it be more a firefox bug, or a JS bug? i.e. do we think we can fix the
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 Feb 11
5
after_(read|find) callback?
I am pondering the possibility of encrypting/decrypting some fields in a SQLite backend on-the-fly. The point of the message is not security, I know that''s broken, but whether there''s a technique that provides on-the-fly save/read filters. Of course the solution would need to work transparently in joins, so user.posts.last.title would do the right thing if title
2006 Aug 25
7
disabling automatic indexing in acts_as_ferret
I''d like to be able to enable/disable the automatic indexing of documents acts_as_ferret does. Something like MyModel.disable_indexing MyModel.enable_indexing would be perfect. I need this because I do some indexing that requires visiting the parents of the model objects and my import method imports the children first, so the information isn''t there yet. I''d like to
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
2011 Oct 14
2
before_save :encrypt_password
I am having a problem finding the best way to make a "before_save :encrypt_password" conditional. I have to at times update user model attributes but each time I do this the password is reencrypted because of the above. I need to differentiate between when the user is first logging in and the password does need to be encrypted, and when they are already logged in and the
2009 Feb 07
5
before_save :strip_whitespace => saves with spaces
i used this private function for removing leading and trailing white spaces from the values.that below function would be called before_save. when i print the value after it strips.it prints string without any spaces.but in the table fields it saves with spaces . waht would be the problem.pls help me class CompanyInfo < ActiveRecord::Base before_save :strip_whitespace def strip_whitespace
2006 Jan 16
1
switchtower custom tasks question.
hi, i''m just getting started using switchtower for deployment. i''m working with a small team of 3 and a hosted subversion repository. i have switchtower working, but i need to create two custom tasks and have those tasks run at deployment. 1) copy a working dispatch.fcgi from another folder, and 2) copy db/database.example to db/database.yml here is what i''ve tried,
2006 Feb 10
4
before_save gotcha
Is it will known and accepted that before_save triggers should return true? I didn''t notice this before but now I see it in the documentation. Here is what I''m doing in my model: def before_save if self.has_album? self.visible = self.album.visible? end end That results in the expected result when album.visible? is true - but not when it is false. To make it
2007 Jun 27
3
acts_as_tree and before_save
We all know that acts_as_tree gives us ability to set up data in a tree-like structure and use methods like ''parent'', ''children'' and so on. Something I''m completely stuck on. Observe. class Page < ActiveRecord::Base acts_as_tree def before_save raise self.parent.to_yaml end end Well, you''d think that it should show
2012 Nov 10
6
Suggestion: `before_save on: :create` should either work or raise an exception
There''s a small inconsistency in ActiveRecord''s callback syntax that has tripped me up before. It wouldn''t be a big deal, but it can lead to a silent failure. I''d like to suggest that it either be made consistent or be made to fail loudly. The issue is that to do something before validating, but only when creating, you use `before_validation on: :create`,
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 =
2008 Apr 30
6
best practice for object transaction?
I have a new @offer that needs to generate a document if saved. But that''s all or nothing: transaction do @offer.save! generate_document end # handle exceptions if needed If save! fails everything is fine, but if generate_document raises an exception @offer is left as a model with timestamps, id, which is not a new_record? anymore (though the database was
2006 Feb 19
2
how would you implement this normalizer?
Names of models in my application have accented characters that imply unexpected orderings. For instance ?vila should go before Madrid, but String#<=> puts it the other way aroud. I am only sorting for views, so it would be OK to do some normalization on-the-fly on Ruby land, and since the same criteria has to be used throughout the application I was thinking on some sort of
2006 Aug 09
7
function before_save
Hi everybody I would like a function as the "before_save" method in the model. But it must be the opposite. When I take out data from the database through the model, I want to call a function before the data are available in the controller. Can anyone help me? ---- >>>> thx <<<< ---- -- Posted via http://www.ruby-forum.com/.
2008 Jun 20
15
before_save model callback rspec testing
hi all, i''m learning rspec and i can''t figure out how to test if a callback is executed in a model. my model code is: class User < ActiveRecord::Base before_save :encrypt_password ... def encrypt(password) self.class.encrypt(password, salt) end thanks a lot, cs. -- Posted via http://www.ruby-forum.com/.
2012 May 12
12
before_save messing up
#user.rb ------> Model class User < ActiveRecord::Base attr_accessible :email, :name, :password, :password_confirmation has_secure_password before_save :create_remember_token . . . . . . . private def create_remember_token self.remember_token = SecureRandom.urlsafe_base64 end end #sessions_controller.rb ------->
2010 Dec 14
5
Build associated model confusion
I''m new to Rails3, and I''m just trying to get one last thing to work before I call it a night. The situation is the following (please if the code is horrible, just let me know, still learning): I want to log a dive. I might have a new location on that dive at which point I have to create a new Location, and then create the dive. A dive has_one location. A location has_many