Displaying 20 results from an estimated 34 matches for "validate_on_create".
2011 Apr 28
3
difference between validate and validate_on_create
i just ran into a problem with some test, and i am not exactly sure why,
but the difference happened when i changed my model validation from:
validate :custom_validation
to:
validate_on_create :custom_validation
can someone give me any ideas on where in the chain the validation takes
place?
thanks!
--
Posted via http://www.ruby-forum.com/.
2006 Apr 07
6
validation nightmare
Please help, I am really at a loss at how validation is supposed to work
in rails.
Model contains
acts_as_tree
I want to force my NEW objects to have a parent
I do NOT want existing object to have a parent
so I only want to have parent_id on create, NOT on update.
I am trying this:
def validate_on_create
validates_presence_of :parent_id, :message => "You must specify a
parent for this keyword."
end
and I get:
undefined method `validates_presence_of'' for #<Keyword:0xb774aba0>
The only time it works is if I remove validate_on_create, but then I can
no long...
2006 Mar 16
2
Verifying existance of related record
...make
sure the user has entered a vaild category (i.e. a category that exists
in the categories table). So in the model of the table I put this:
class Master < ActiveRecord::Base
belongs_to :category, :foreign_key => "categoryid"
validates_presence_of :categoryid
def validate_on_create
unless Category.find(:first, :conditions => "categoryid = #{categoryid}")
errors.add(:categoryid, "is not a valid category id")
end
end
end
However this does not work because the "validate_on_create" is being run
before the "validates_presen...
2008 Nov 19
2
Where should I put "prerequisite logic"?
...d the create_item action) I
need to update others tables and make lookups in other tables, to check
if the Character has the prerequisites to actually create the
InventoryItem.
My problem is that I cannot seem to find a good place to put this logic.
I''ve tried to put it in a InventoryItem#validate_on_create. This is a
hassle, because the InventoryItem has no direct association to all the
things it need to check/update. Also, isn''t it against the guide lines
that validations actually updates/changes stuff as it is required here?
I''ve also tried placing most of the logic in the create...
2006 May 04
2
validates :on 2
Hello, I need to have this for :create and :login how do I do so
validates_presence_of :login, :password, :password_confirmation,
:user_name, :email, :on => :create
I do need it to be off in a number of places though
--
Posted via http://www.ruby-forum.com/.
2006 Dec 07
2
validate_on_destroy ?
What''s the best way to validate_on_destroy. Rails only seems to include
validate_on_create and validate_on_update methods. I don''t want to
resort to doing:
before_destroy do |j|
raise "There is an error" if j.etc
end
Is there a way of finding out what action (create/update/destroy) is
being performed if I use the ''validate'' method?
--
Posted via ht...
2006 Oct 07
3
blog_id magic with typo
...l save, the value printed by logger.info is
"**** and blog id in article is 2".But after @article.save is
called...whatever may be the current blog_id, the value that gets
stored in database is always 1. And I have no clue, why is this.
Another pointer. In content.rb model i have defined validate_on_create
callback and here goes code for that:
def validate_on_create
logger.info("$$$ and blog id in article after save is #{self.blog_id}")
# my own financial domain kung-fu
end
so...the above code also prints blog_id as 2 just before saving the
article. But again...the value that goes...
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
2007 Mar 28
4
Disabling ActiveRecord "type" column subclassing
Hi! I have a legacy table that has a column named "type" and need to
remove this automatic subclassing by ActiveRecord. The api pages are
vague about this, and I tried
self.inheritance_column = "xtype"
which seemed to get me half-way. In the validate_on_create method, the
value of self.type was my model Class name.
How would you disable this feature?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" g...
2006 Feb 03
2
validation only on a specific action
Hello again!
I have a action that lists users and that allows an admin user to create
new users. When the admin user creates a new user an e-mail is sent to
the created user telling him to register in the site. I want to validate
the user name and password only when the user register and not when the
admin user creates it. Can anyone tell me how to do this?
Thanks.
Best regards,
Hugo
--
2005 Dec 30
2
before_create question
I have the following models: User, Registration, Event.
User has_many Registration, Event has_many Registration, and
Registration belongs_to User and Registration. So far, so good.
There''s a registration deadline on a Event though, a few days before
the Event occurs.
So, I have this:
class Registration < AR
def before_create
errors.add_to_base("Registration deadline has
2005 Sep 27
2
No Custom Validation
Hi,
Correct me if I am wrong but there doesn''t seem to be an easy way to add
validation outside the pre-built ones (validates_presence_of,
validates_lenght_of, etc.).
Ideally there should be something like:
Class Person < ActiveRecord::Base
validates :my_method, :on => create, :message => ''was not valid''
def my_method(param)
false unless
2006 Jan 19
2
Easy way to handle form input without a model class?
I have a couple forms that I''d like to be able to validate and
automatically populate, but it shouldn''t be based on AR. In fact I
often have a bunch of small forms that I can''t really justify writing
a whole new model class for anyway. I''d like to validate the form
input, and then use rails helpers to automatically populate the form
if validations fail.
2005 Dec 02
8
UserEngine: stack level too deep
...e trace:
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:682:in
`|''
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:682:in
`write_inheritable_set''
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:240:in
`validate_on_create''
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:379:in
`send''
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:379:in
`validates_presence_of''
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:378:i...
2006 Jul 25
1
How do I validate using associated objects?
...comment.board.setting(:reply_thumbnail_at_width)
y = comment.board.setting(:reply_thumbnail_at_height)
end
if @thumbnail.columns > x or @thumbnail.rows > y
@thumbnail.change_geometry!("#{x}x#{y}") {|cols, rows, img|
img.resize!(cols, rows)}
end
end
def validate_on_create
errors.add_to_base(comment.board.language(:error_toobig)) if
self[:image_width] > comment.board.setting(:maximum_image_width)
end
end
--
Posted via http://www.ruby-forum.com/.
2006 Jun 19
2
call validate functions
Hi
on the code below the validates all the form fields
if @client.save
flash[:notice] = ''Client was successfully created.''
redirect_to :action => ''list''
else
render :action => ''new''
end
how can I do this action without having to save the object?
ie
if validate
#move on to next stage
else
redner
2006 Apr 13
0
Model with file uploads
...What do you think of this? Any suggestions?
class Video < ActiveRecord::Base
acts_as_taggable
attr_accessor :field_tags
attr_accessor :field_thumb
attr_accessor :field_video
validates_presence_of :title
validates_presence_of :description
validates_presence_of :field_tags
def validate_on_create
errors.add ''field_thumb'', ''Invalid thumb'' unless
!self.field_thumb.read.empty?
errors.add ''field_video'', ''Invalid video'' unless
!self.field_video.read.empty?
end
def after_create
self.tag_with self.all_tags...
2006 Mar 02
3
validates_uniqeness_of
Hello,
I am trying to understand usage of validates_uniqeness_of.
Say I have, two column ''name'' and ''email'' in my table users
three unique key is possible for these two columns
1. name
2. email
3. name and email together
My question is,
if I write
validates_uniqueness_of :name, :email
what uniqueness is it going to apply,
1 and 2
or,
3 ?
Thanks,
Mohammad
2006 Feb 02
1
tricky form validation
Hi list,
I want to create a form validation in my Marketing Model.
I want to raise an error only if a previous marketing campaign for a
property has not been completed (ie. ended_on IS NULL)
I managed to get this working in the Controller using something this:
...
if Marketing.count("property_id = #{@marketing.property_id} AND ended_on
IS NULL") > 0
...
However I assume
2006 Feb 21
1
Custom forms and fieldWithErrors tags
...an store the information from the forms, and some checks:
Model (part of it):
attr_accessor :local_part
attr_accessor :domain_part
validates_presence_of :local_part, :on => :create
validates_format_of :local_part, :with =>
/^[_\.-abcdef..(cut)...890]+$/, :on => :create
def validate_on_create
em = Mail.find_by_email_address(email_address)
errors.add :local_part, ''Email already taken'' if !em.nil?
end
... and then compose the real email address in the controller on the submit
action, like:
Controller:
@email = Mail.new
@email.attributes= @params['...