Displaying 20 results from an estimated 7000 matches similar to: "validates_presence_of in a mixed-in module?"
2006 Feb 07
4
Ruby, Rails & Inheritance
Hi!
I am looking for a solution for the following problem:
Some of my models share some attributes and also was in need for some
extra features, so I created a class "RecordWithFeatures":
-----------------------------------------------------------------
class RecordWithFeatures < ActiveRecord::Base
# @Override
def self.descends_from_active_record?
superclass ==
2006 May 17
3
Help mixin in class methods
Starting to feel more confident and code is DRYing up nicely, but I''ve
hit a brick wall here and hoping someone can help me.
I''ve got a module, TrustRanking, which extends a number of model''s
instance methods, and I want to extend their class methods too, but I
can seem to work out how to do it.
Simply including the module from the class works a treat for the
2006 Jul 27
9
Introspecting validates_presence_of
Hello people,
I''d like to detect whether an attribute of a model has
vaildates_presence_of applied to it so I can automatically apply a
mandatory (*) to the field...it doesn''t look easy...any ideas?
Cheers,
--
Dan Webb
http://www.danwebb.net
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
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
2005 Dec 19
2
Validation that works in the controller
Hi,
Is there a way of validating input inside the controller? or an equivalent to
ActiveRecord::Validations::ClassMethods.validates_presence_of ?
Cheers,
-- Colin
2006 Feb 01
7
Explanation of "alias_method"
Hi!
I''m trying to extend ActiveRecord''s find method (Rails 1.0, Ruby 1.8.2),
but I recognize a strange behaviour of the "alias_method" call.
I wrote a very simple script to explain my problem:
------------------------------------------------------
module ActiveRecordExtension
def self.included(base)
base.extend(ClassMethods)
base.class_eval do
2006 Apr 18
4
Mixin variables
I''ve created an access control module that I''m including in several
different controllers. Everything works fine, but I want to allow each
controller to override the default login page with something like this:
set_login_pages :secure => ''my_login''
In my module, I''ve set up the set_login_pages method like this:
def self.included(base)
2006 Mar 15
4
[NQ] How to set an initial FK for a new item of something?
Hi all,
running into a little problem here. I''ve a list of things
with a "New thing" link beneath it. When you click that link,
obviously, a new thing shall be created. Now, that works pretty
fine for things that don''t have foreign keys, but for things that
do it crashes, since there is not yet a thing.other_thing.name
available.
I suspect you can somewhere in
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/.
2011 Apr 27
2
Can not create model instance via params on specific model but can on others....
Anyone have an idea on this? Got a weird situation where on a specific model
I can not create an instance using params, yet it works fine on other
models. The model which does not work is a stock model, there is no logic in
it. Ruby 1.8.7/Rails 3.0.5.
Does not work:
(rdb:1) PaymentTransaction.create(:purchase_id => 3)
#<PaymentTransaction id: 2, purchase_id: nil, action: nil, amount: nil,
2010 Mar 10
2
"must be nil" validation?
Hey guys, is there a validation that essentially acts the opposite way
of "validates_presence_of". That is, the attribute in question must be
nil, or blank, non-existent. If not, what''s the best way to prevent a
user from altering a web form attempting to submit data to a field
that they should never have access to?
Thanks!
--
You received this message because you are
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
2007 Oct 16
12
Example for attr_accessible?
Is anyone out there writing specs to check attr_accessible fields? I had
originally written my spec to check for allowing the desired fields, and
then none of the other regular db fields. Unfortunately this isn''t
satisfactory, because attr_protected could have been used instead, which
of course wouldn''t prevent mass assignment to any whatever=(val) method.
I''m thinking
2009 Jan 03
0
understanding rails internal architecture
i am currently digging into the rails 2.2.2 source to get a deeper
understanding of some features (in particular model-validation) and a
better overall insight. most of rails features are encapsulated in a
separate module - as far as can see - and wired together through
mixins. this makes sense and following the logic in the single modules
is easy. but i am getting stuck while puzzling to see it
2005 Dec 16
4
Validation with Aggregation
ActiveRecord supports composed_of for value objects which is
fantastic but one thing that it doesn''t seem to support (or at least
I am unable to find any documentation for) validation of the value
objects.
For example, given the following:
class Message < ActiveRecord::Base
composed_of :sender, :class_name => ''EmailAddress''
composed_of :recipient,
2006 Jun 13
6
Dead horse: validates_associated
Regarding validates_associated...
Let''s say I have:
article belongs_to author
But for whatever reason, I want an article to also be written
anonymously and therefore not require an author. Then I have:
Article:
belongs_to :author
validates_associated :author
But I DON''T have validates_presence_of. What I want to do is validate
that an author is valid --if it is
2006 Feb 28
6
How To Validate Boolean Form Field
Hello all.
I''ve got the following in my model:
class Individual < ActiveRecord::Base
validates_presence_of :first_name, :last_name, :street, :city,
:state, :zip
validates_acceptance_of :AZ_resident, :message => "You must be an
Arizona resident."
end
The AZ_resident field is present and defined as boolean (PostgreSQL
8.1), but validation will not occur.
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