Displaying 20 results from an estimated 30000 matches similar to: "problem with validates_presence_of :on=> :update"
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 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 trying to get to happen is
if one is there they all must be
2006 Oct 26
0
Recipes authentication & validates_presence_of
I''ve implemented Rails Recipe #31, Authentication, and I found that
validating password and password_confirmation just doesn’t work while
the method ‘password=(pass)’ is in the mix, but I need that for the
salt/hashing, no?
If I don’t use validations, the password gets hashed, salted and stored
in the database fine. I can login with same username/password.
However, if I want to
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 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 15
0
Re: rails question
Hi Shelby,
No prob,
You are having trouble b/c you don''t call @festival.valid? before this line:
if !(@festival.errors.invalid? :name ) # => true if name is invalid
I wasn''t clear about it in my post, but ActiveRecord::Errors#invalid? doesn''t actually do validations. It just looks at the associated errors object (which is empty if validation hasn''t
2007 Jan 23
0
validates_presence_of fields. in parent ok, but how in children?
i have the problem that my child class fileds aren''t validated on
saving the
parent. working with parent and child works without problems.
if all fields are filled correctly everything is saved as expected.
but missing fields in the child arent added to the errors.
following short sample shows what i try:
Model
-----------------------------------------------------
class Parent <
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 14
0
if condition on validates_presence_of is not working
class Event < ActiveRecord::Base
attr_accessor :step_processing
validates_presence_of :name,:description , :if => (:step_processing ==
4)
end
class TestController < ApplicationController
def bar
@event = Event.new
@event.step_processing = 4
@event.name = ''foo''
@event.save
end
end
In the above code :step_processing a non-database field. It''s
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
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 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
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
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 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 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?
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 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 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?