similar to: before before_validation callback

Displaying 20 results from an estimated 7000 matches similar to: "before before_validation callback"

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`,
2012 May 26
2
before_create is after_validatation :on => :create , when it should be before_validation :on => :create
In ActiveRecord''s callbacks, methods within a before_create callback are called after the validation, but before the model is created. This was an intentional design decision, but I think it was the wrong one. What do you think? When I think of before_create, I think of before_validation :foo, :on => :create, but, by default, before_create is synonymous with after_validation :foo,
2006 Mar 24
1
Problems with before_validation
Hi all My visitors can create party organisator profiles, and I want assign them as the creators (the field creator_id in the organisators table references a member in the members table). To do that I tried it with before_validation: def before_validation creator = Member.find 1 end Sadly, this does not work. The validation validates_presence_of :creator_id Still tells me, that
2007 May 28
2
out-cheat validates_uniqueness_of
before_save :strip_strings validates_uniqueness_of :username validates_presence_of :username private def strip_strings self.username = username.gsub!(" ","") end example: username = " gissmoh-/upiLifMog2ELgA04lAiVw@public.gmane.org " becomes gissmoh-/upiLifMog2ELgA04lAiVw@public.gmane.org and is stored in the
2009 Jun 24
2
At my wits end ! Controlling passed in negative values from a form
Hi, I am trying to validate a numeric value passed in from a form, which is saved in a MySQL db as decimal(9,2) Now problem is I need to ensure people don''t enter a form value like -. 003. In my validations, I have a validates_numericality_of check being done. Furthermore, in validate method, I have a check using an if statement such as : ((an_object[n].nil? or an_object[n] < 0) and
2006 Sep 06
6
validates_presence_of question
Can I use validates_presence_of somehow if I want to check that at least one of 2 fields is not empty? Thanks, Dmitry -- 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
2007 Apr 05
0
unexpected behavior of before_validation
Today I found these comments in active record''s callbacks.rb file: # If the returning value of a before_validation callback can be evaluated to false, the process will be aborted and Base#save will return false. # If Base#save! is called it will raise a RecordNotSave error. # Nothing will be appended to the errors object. This caused me a lot of frustration earlier when I was
2006 May 09
11
model filter?
Hi All, Is there a way to filter / modify the output of a model class before it''s returned to controller/view that''s calling it? Example: I have a field phone_number which I always want to preformat using the number_to_phone() helper.... Any help is appriciated. Thanks! -- 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/.
2006 Mar 25
0
[Sentry]-before_validation(model) not working for crypted-attribute?
I am still trying to get sentry working to encrypt a couple of attributes in the model. One of them is a password field and the other ssn#. I have crypted_password and crypted_ssn in the db. In addition, I also have validates_uniqueness_of :ssn Here is the problem... I get the error MysqlError: Unknown column ''ssn'' in ''where clause'': SELECT * FROM students
2006 Apr 27
3
Removing a default value for a foreign key with not null set
Hi all, For various reasons I need to have foreign keys with not null constraints. Eg: create_table :people do |t| t.column :name, :string t.column :household_id, :integer, :null => false end create_table :households do |t| t.column :name, :string end add_foreign_key_constraint :people, :household_id, :households, :id So the people table has a foreign key into
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
2005 Dec 20
2
Null Text Fields
I tend to allow nulls in cases where the value is unknown, even if it''s a text/varchar field. RoR seems to push empty strings into these fields. Is there any way to get RoR to use NULL vice '''' if the input box is empty? Thanks! - Ian
2008 Apr 17
1
Callback Problem: Why to use self.var= instead of @var=
Hi, I''ve defined the following model: class Eintrag < ActiveRecord::Base before_validation :vali protected def vali # self.feld1.reverse! self.feld2 = self.feld1 end end Now I''m wondering why I have to write self.feld2=self.feld1 and why @feld2=@feld1 doesn''t work. I''ve found the thread
2007 Feb 23
2
how to remove spaces from phone number
Hi, I need to allow login based on the phone number. During the signup they can give the number in any format with spaces, slash or (). But for storing in database and then during login to compare I just want the 10 digit number. How can I remove the special char from phone number before storing to db ? Thanks. -- Posted via http://www.ruby-forum.com/.
2006 Apr 30
0
populating model attribute from one of many lists
I have a model named Project which contains a name attribute, and I have a second model named Booking which has, among other things, a date and a Project. (has_many :bookings, belongs_to :project). When a user creates a new Booking, they have the option of using an existing Project or creating a new Project. As an added complexity, when choosing from existing Projects, they can either choose from
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
2006 Jan 30
9
Something as after_successful_validation?
I need to call callback only if the validation was successful, but it seems it is called also when validation fails. -- Posted via http://www.ruby-forum.com/.
2006 Apr 08
4
Calling validates_inclusion_of out of default namespace
Hi, I''m trying to run the "validates_inclusion_of" method in a before_save hook, because the range is dependant on the related data. But I can''t figure out how to call it. When calling it normally, it says it can''t find it. I''ve tried several combinations like "ActiveRecord::Validations.validates_inclusion_of", but I can''t seem to
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