Displaying 20 results from an estimated 491 matches for "validates_presence_of".
2006 Aug 10
4
I need "validates_presence_of" help
Hi - I have 3 fileds a user can fill out. They can fill out 2 of them or
just one of them, for example.
fill out these 2 fields:
Field1 and Field2
Or fill out this field:
Field3
In my model how do I use validates_presence_of for Field1 and Field2 or
just Field3.
I want to do something like this:
validates_presence_of Field1, Field2
OR
validates_presence_of Field3
So the user can fill out Field1, Field2 and be a succesful update or
just fill out Field3 and be a succesful update. Any help will be
apreciated, thank...
2006 Mar 25
3
validates_presence_of validation order?
I have a form with 3 fields: user_id, email and password.
All 3 fields are required, so I have a "validates_presence_of :user_id,
:email, :password" in my model.
Works, but the validation errors show up in a different order than I
specificed in the validates_presence_of statement.
Is there a way to specify the order in which the validations (and
corresponding error messages) should occur using the built in...
2006 Mar 13
4
undefined method `validates_presence_of'' for #<ProductsContr
Hi,
I am trying to use method `validates_presence_of'' for validating my
input fields on form . I m using it in my action class as follows:-
=======================
validates_presence_of(params[:product][:quantity])
======================
But when I am running my application i m getting error like:-
=========================
undefined metho...
2006 May 18
1
Introspection of validates_presence_of
Hello all.
I don''t know how to get all symbols passed to method
validates_presence_of in model. I''ve trying to use following solution:
class News < ActiveRecord::Base
validates_presence_of :title, :text
def validates_presence_of(*attr_names)
@@obligatory_fields = attr_names
ActiveRecord::Base.validates_presence_of(*attr_names)
end
def obligatory_fields...
2006 May 22
2
Weirdness with validates_presence_of
Hi,
I have a call to validates_presence_of in my model and it is behaving very
strangely
my first stab when this happened during testing was
validates_presence_of :impact, :ease_to_implement if Proc.new { |record|
!record.cost_estimate.nil? }
I have three values in my model that I care about with this one. Basically
what I''m tr...
2006 Apr 07
6
validation nightmare
...y 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 longer update existing entries t...
2006 Aug 09
6
How to change the error message easy way
validates_presence_of :fname
results in the error message
"Fname can''t be blank".
What I want is "First Name can''t be blank".
I could do this
def validate
errors.add_to_base("First Name can''t be blank") if fname.blank?
end
I find this clunky and I have to...
2008 Nov 01
2
stuck on a validates_presence_of unless issue
i have a person object. Persons don''t need to have addresses, but if
they have any address field value, they must have them all. So I have
something like this:
validates_presence_of :street_address, :city, :state, :postal_code
unless :address_blank?
address_blank? checks whether all of the address fields are blank.
If I run a test like this, it works:
describe "given attributes" do
before(:each) do
@valid_attributes = {
:first_name => "...
2006 Jun 07
1
validates_presence_of in a mixed-in module?
...s
includes [the module] Ranking. Then the module Ranking has a bunch of
instance methods and a submodule ClassMethods. The ClassMethods in this
are mixed in to the class with self.included. So far so good.
But I want the module to contain some validation definitions (using the
built in methods validates_presence_of etc) for the classes that are
mixin it in. Have tried putting them in the ClassMethods and the
instance methods, and both throw up NoMethodError when I start up the
console.
Anyone able to help?
2006 Jan 19
4
validates_presence_of
...me across a problem with the
code in the app/models:
validates_format_of :image_url,
:with => %r{^http:.+\.(gif|jpg|png)$}i,
:message => "must be a URL for a GIF, JPG, or PNG image"
It seems to moan when it''s empty even though I removed :image_url from
validates_presence_of. How should I make it optional? Altering the
regex?
Btw I have the same sort of problem with example code for the price
example. I want it optional unless I used validates_presence_of. Isn''t
that sensible?
In the SQL DDL, does NOT NULL mean anything here?
2009 Jan 09
3
What is wrong with validates_presence_of :my_association ?
Category.has_many :products
Let''s say a product must belong to a category. I know it is recommended
to do the following:
class Product
validates_presence_of :category_id
end
But, as we all know, this is a pain for new records, meaning what if the
associated category is a new record?
I''ve been meaning to ask this, but what''s wrong with doing the
following:
class Product
validates_presence_of :category
end
I never understood why tha...
2006 Mar 14
3
Can anybody tell me step by step how validate data on form?
Hi,
I am new to ROR. I have created a form with foru fields in ROR. Now its
working fine for all CRUD operations. But I want to validate data on
form for "validates_presence_of" validation. How to do this?
I tried it by putting line "validates_presence_of :description" . But
its not working. Its throws error like "undefined method `each'' for
nil:NilClass"
Also what is ":description" in the "validates_presence_of :desc...
2006 Apr 12
0
How to get validates_presence_of worked in this situation?
Suppose:
class articles < ActiveRecord::Base
has_many :assistarticles
validates_presence_of :body
end
class assistarticles < ActiveRecord::Base
belongs_to :article
validates_presence_of :detail
end
In the submit form:
<%= text_field ''article'', ''body'' %>
<%= text_field ''assistarticle'', ''detail''...
2006 Apr 23
3
Validates_presence_of in ActionMailer model
Hi all,
I want to submit the content of a form by mail.
I don''t want to save it into a DB.
How can I validates the content of this form with validates_presence_of ?
Thank you.
Damien
2009 Jul 04
9
prevent orphan records
If I have
belongs_to :user
Do I need to have
validates_presence_of :user_id
?
Does Rails validate the presence of :user_id automatically if I have
belongs_to :user?
In other words, does Rails prevent against creating orphan records that
belong to non-existent users?
Thanks.
--
Posted via http://www.ruby-forum.com/.
2006 Jul 27
2
Creating multiple objects from form data
I''m in the process of creating a sign up form for an online application.
The form collects account info, company info, and then info for an
administrative user.
The method looks like this:
def create
@account = Account.create!(params[:account])
@company = @account.companies.create!(params[:company])
@user = @company.users.create!(params[:user])
end
However, this inevitably fails
2009 Feb 19
3
Associated child records not created on creation of a parent.
...l < ActiveRecord::Base
2. belongs_to :author, :class_name => ''User''
3. has_many :departments
4. belongs_to :prototype_model
5. acts_as_tree :foreign_key => "parent_id"
6. end
Code :
1. class Department < ActiveRecord::Base
2. validates_presence_of :name, :description
3. validates_presence_of :parent_id
4. acts_as_tree :foreign_key => "parent_id"
5. belongs_to :department
6. belongs_to :prototype_model
7. end
Code :
1. # POST /prototype_models
2. # POST /prototype_models.xml
3. def create...
2007 Jun 21
1
Validation Through Multiple Models from one Form
Hey All,
I have a form that submits data to multiple models.
I have
class Man < ActiveRecord::Base
has_many :notes
has_many :contacts
validates_associated :contacts, :notes
validates_presence_of :first_name
validates_presence_of :last_name
class Contact < ActiveRecord::Base
belongs_to :man
validates_presence_of :contact_info
class Note < ActiveRecord::Base
belongs_to :man
validates_presence_of :notes
However when I submit the form blank, it will only valida...
2007 May 11
4
"validates_presence_of" not working
Hi, guys,
I''m learning to use Rails, and, while reading the "Rails: Up And
Running" book, I tried to make an insertion validation, using the
following code:
class Photo < ActiveRecord::Base
validates_presence_of :filename
end
It simply didn''t work, the validation does nothing and an insertion
with an empty field returns TRUE.
What''s wrong?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails...
2007 Oct 17
3
validates_presence_of validating twice?
I''m getting some weird behavior in one of my models. I have a model
defined something like this
class User < ActiveRecord::Base
attr_accessor :password
validates_presence_of :password
end
If I validate the model without specifying a password, I get ["can''t be
blank", "can''t be blank"] for :password instead of just one "cant''t be
blank". If I comment out the validates_presence_of statement, then no
errors. So it...