Displaying 20 results from an estimated 4000 matches similar to: "Weirdness with validates_presence_of"
2009 Jan 12
2
validates_presence_of fails with false boolean
This almost feels like a bug to me, since false is not nil. (i don''t
think!) Using v_p_o on a boolean field fails validation if the field is
passed with ''false''. It passes validation in the case of true. How can
I validate _presence_of a boolean if it is submitted false?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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 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
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 method `validates_presence_of'' for
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
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
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
2006 Jan 19
4
validates_presence_of
I am just going through the book and I come 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?
2006 Jun 07
1
validates_presence_of in a mixed-in module?
Anyone got any idea of how to use built-in validation methods in a
mixed-in module.
What I''ve got at the moment is each class that needs ranking methods
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
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
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
2007 May 08
3
How to restore fields ("validates_presence_of")
Hi all,
I am using "validates_presence_of" for validating all fields of my
registration form. It is working fine and generating custom error
message as mentioned.
Also clearing all fields. How can restore those fields which are already
filled.
Problem is "validates_presence_of" clearing (blank) field if it fails,
instead of restoring fields which are already filled.
Help.
2006 Jan 03
6
Am I going too far or Rails is just confusing? was {validates_presence_of *_id attributes}
Thanks for the input Blair Zajac and Chris (Nolan and Hall), and for others.
If all of you have time, please follow this (the question still
relates to the previous posts by me):
I have provided full steps to reproduce the symptoms.
If it matters, I''m running Ruby 1.8.2, Rails 1.0, and MySQL 5.0.15 on
Windows XP Professional.
1. First, the setup
MySQL
-----
create database testdb;
2007 Feb 26
2
boolean db fields set to false fail validation with validates_presence_of?
I have a model that contains a :boolean field. In my view, I have a
simple select of Yes or No, which equates to true or false,
respectively. If I choose yes and save, everything works great. If I
choose no, my model fails validation as I have this set as a required
field using validates_presence_of. I have checked the log and it''s
definitely set to false, why would this fail validation?
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
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?
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
2006 May 19
1
validates_presence_of and ajax-forms
Hi.
I have "validates_presence_of :login, :password, :firstname,
:lastname" in my user-model. I enter the information in
new_user.rhtml:
<%= error_messages_for(:user) %>
<%= form_remote_tag :url => { :action => :register }, :html => { :id
=> ''new_user'' } %>
I have a register.rjs with :fade.
Omitting firstname or any other required field
2006 Apr 19
1
validates_presence_of
Hi, having a few problems working out whats kicking off,
im using validates_presence_of :title in a models class
this seemed to work fine untill I used a custom new.rhtml
error message I am gaining is
NoMethodError in Recipe#create
Showing app/views/recipe/new.rhtml where line #15 raised:
You have a nil object when you didn''t expect it!
You might have expected an instance of Array.
2006 Mar 22
3
Problems with validates_presence_of...anybody?
Hello everybody,
I have been developing small applications in Rails from quite some time.
But lately, I came across a bug which I have not been able to correct.
If anybody could help me with it, would be of great help thankyou.
Actually, the problem is that I have a form in my application with some
set of fields.
Now what "validates_presence_of" should do is that if I submit the form