Displaying 17 results from an estimated 17 matches for "after_validation".
2006 Aug 14
2
after_create is not being called
...description, :file_path, :title_photo_id
has_many :photos, :dependent => :destroy
belongs_to :title_photo,
:class_name => ''Photo'',
:foreign_key => ''title_photo_id''
validates_presence_of :title, :description, :file_path
def after_validation
if !errors.invalid?("file_path")
images = get_images
if images.size == 0
errors.add_to_base("There are no files in the directory
#{get_images_path}")
else
errors.add_to_base(images.inspect)
end
end
rescue SystemCallError
err...
2012 May 26
2
before_create is after_validatation :on => :create , when it should be before_validation :on => :create
...ck
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, :on => :create`, which is technically correct,
but confusing. Most of the goal of convention over configuration is to
have sane defaults, right? Wouldn''t following that principle include
favoring what makes the most sense at first thought, over a
technicality?
And, I''m c...
2006 Feb 22
0
STI and Inheritance
...ct.
Basically I am using STI on my Users table and have several types of users.
BaseUser
--UserType1 < BaseUser
--UserType2 < BaseUser
etc....
Recently when I create a UserType object and save it to the database it
ignores the validation rules for the parent class BaseUser. Furthermore the
after_validation method in the BaseUser was not being triggered if I did:
after_validation :run_this
I had to call the run_this method after_validation to get it to trigger.
Any suggestions or thoughts on this would be greatly appreciated.
Thx,
--
Ben Reubenstein
http://www.benr75.com
-------------- next part...
2008 Feb 03
1
ActiveRecord object.valid? triggers unexepected results
...;'m editing an ActiveRecord object in a session through AJAX, updating
it with object.attributes = params[:object], and validating it with
object.valid?
Because it''s associated with other objects in a form, I want to save
them all together.
The surprise was that object.valid? triggers after_validation_on_update.
I''m having an audit log and I was getting bogus entries.
http://api.rubyonrails.org/classes/ActiveRecord/Validations.html#M001316
valid?()
Runs validate and validate_on_create or validate_on_update and returns
true if no errors were added otherwise false.
valid?() should run a...
2006 Jul 17
1
How to DRY up validates_presence_of
Given the case of validating the presence of an attribute and then
performing other tests on said attribute, how do you go about not having
to check for nil in the other tests?
Example:
validates_presence_of :start_date, :end_date
validate :validate_start_date_before_end_date
def validate_start_date_before_end_date
# without this check an exception will be thrown on access to the
2006 Jun 09
0
difference between @secure_password, secure_password
Hello,
I have a User object that extends ActiveRecord::Base.
And I have the following defined in it:
....
after_validation :crypt_password
...
def crypt_password
# write_attribute("secure_password", User.encrypt(password))
self.secure_password = User.encrypt(password)
end
..
And this works. Where I am getting confused about is the difference
between the following:
secure_password,
@sec...
2009 Jul 07
2
paperclip unit testing
Hi,
Rails 2.3.2, paperclip 2.2.9.2
How can I unit test my model that has a paperclip attachment?
I add to my model:
--- CODE START ---
has_attached_file :image, :default_url => ''''
attr_protected :image_file_name, :image_content_type, :image_image_size
--- CODE END ---
Than I type a UNIT test:
--- CODE START ---
foo=FooModel.new({:image =>
2006 May 24
1
Observer behavior differences between DEV and TEST environments ?
...ent.rb,
but things don''t work...
So, I took a step back and put in the following code:
class GreenbackTransactionObserver < ActiveRecord::Observer
%w( after_find after_initialize before_save after_save
before_create after_create before_update after_update
before_validation after_validation before_validation_on_create
after_validation_on_create
before_validation_on_update after_validation_on_update
before_destroy after_destroy ).each do |method|
define_method(method) do |txn|
txn.logger.info "#{method} (observer)"
true
end
end
end
My model look...
2010 Aug 30
9
Validates numericality issue
Hello everyone I have a problem in my app with the validation on
numericality. The field should be all numbers, and if an user types for
example "12345abc" into the field an error is raised and the data is not
saved. But in the field where the error was raised it now says "12345",
I want this field to be blank instead.
What is the best way to go about doing this?
Thanks in
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/.
2005 Apr 23
7
Validation question
Hi all,
Is there a way to invoke validations at times other than save, create
and update? I know that I can do this by writing my own validation
checks using errors.add_[blah], but I''d like to leverage the existing
validation code.
What I have is two sets of fields in a record, set A and set B. Both
sets must be validated on record create. However, the trouble is that
after
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
2007 May 01
2
Problem validating boolean
Hi
I''ve got a problem validating a boolean and I can''t see what the
problem is. Here''s my model:
class FinanceAgreement < ActiveRecord::Base
belongs_to :asset
validates_presence_of :finance_company
validates_inclusion_of :balance, :in => 0.01..10_000_000
validates_inclusion_of :term, :in => 1..600
validates_numericality_of
2010 Sep 27
5
RoR Tutorial : clear password field
Learning Rails following the Rails Tutorial book I have the following
question.
In chapter 8 at the Exercises part they talk about clearing the
password field.
I tried several things to do this, but till now didn''t find the
solution.
Anyone has a tip how to do this?
Thanks in advance
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails:
2009 Oct 27
5
Unwanted call to validates_associated
In my schema, a question has_many :answers. When the validations are
run on a question, and one of the answers is not valid, then i get
"Answers is not valid"
coming out of errors.full_messages. I don''t want this, i''m already
testing the validity of the answers and this is an ugly and
uninformative error message. It looks like it''s the message i would get
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 =
2013 Jun 25
6
creating an account with a username in devise
Hello, all. I have followed these links and have enabled a (current)
user to login with a username:
http://railscasts.com/episodes/209-introducing-devise
http://railscasts.com/episodes/210-customizing-devise
https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address
I want to allow a user to sign up with a username but am getting these