Displaying 20 results from an estimated 11000 matches similar to: "Validation on composed_of problem"
2005 Dec 17
1
How to use validation with aggregation (composed_of)?
At the risk of being banned for posting the same question twice, I
thought I''d try once more with a question for the title rather than a
statement (on the basis that perhaps questions get answered and
statements ignored ;-) )
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
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 Jul 11
1
Validating composed_of
Hi,
How do I validate a composed_of attribute in my model?
I have a product model with:
composed_of :price, :class_name => ''Money'', :mapping => %w(cents cents)
This maps the price attribute to the Money
(http://dist.leetsoft.com/api/money/) class. I want to make sure that
the price only contains a price to 2 decimal places i.e. 1.25. This is
because if someone enters
2009 Jan 16
1
Aggregation: problem with uninitialized composed_of object
Hi,
I''m getting this error:
>> p = Plan.new
>> p.amount
TypeError: wrong argument type String (expected Fixnum)
Apparently this happens because the aggregation isn''t initialized.
Here''s the code:
class Plan < ActiveRecord::Base
composed_of :amount,
:class_name => "Money",
:converter => Proc.new { |s|
2006 Jul 13
1
Incorrect composed_of I think
I am trying to use composed_of in my model, but I not succeeding.
With the code I pasted below, I cannot perform this action in the console:
property = Property.new(1, "px")
I get NameError: uninitialized constant Property when I try to perform
that action. It''s not finding my class I made I suppose. The Property
class is in the same file as the Element class, element.rb.
2009 Feb 26
1
composed_of, aggregate object isn't saved
I am relatively new to rails and I cannot figure out what is going on
here. I am using the composed_of method in an ActiveRecord class to
create two aggregate properties: shipping_address and billing_address.
The object properties are getting populated from the form and validation
is working - no problem. When I call order.save, though, everything is
being saved except the address fields. I am not
2006 Jul 23
0
composed_of and validates_presence_of
I''m using composed_of in one of my models, and I''d like to validate
that the attribute is present.
class Hand < AR::Base
composed_of :level, :mapping => [ %w(sb sb), %w(bb bb), %w(ante ante) ]
validates_presence_of :level, :message => "must be set"
end
The Level class itself is very simple:
class Level
include Reloadable
attr_reader :sb, :bb, :ante
2006 Mar 16
5
TimeZone, TZInfo, daylight savings, and composed_of
Does anyone know the best way to track time zone information. There doesn''t
seem to be much documentation on this. So far it seems like a simple db
field like
create table accounts (
id int unsigned not null auto_increment,
name varchar(50) not null,
time_zone varchar(50) not null,
...
primary key (id)
)
and a class like
class Account < AR
...
2006 Mar 03
0
unused composed_of bits
I implemented a Temperature model for my application. It is pretty basic,
composed of a temperature, a unit and some conversion methods. In my app model
I decided to store temperature values in Fahrenheit, so there is no need to
remember the units between invocations. I am having a little trouble composing
my app model.
A little bit of my temperature class:
class Temperature
# Composed of
2006 Mar 19
4
Trouble with composed_of
I''m trying to use composed_of within my model. I have a field in my
database named ''card1'', which is simply a string. I have this in my
model
class Player < ActiveRecord::Base
composed_of :card1, :class_name => ''Card''
end
class Card
attr_reader :value, :suit
def initialize(s)
@value = s[0].chr
@suit = s[1].chr
end
end
The
2006 Mar 09
1
[TIP] Making an intelligent form fields
After searching arround I found a quite smart solution to me for binding
form fields to model in an active way. I use aggregations with single
value objects such as
class Percentage
attr_accessor :value
def initialize(value)
@value = (value.is_a? String) ? value.tr('' %'', '''').to_f : value
end
def to_s
return unless value
2006 May 18
1
Patch 5091
Hi,
I submitted a patch (for the first time) a couple of days ago
(http://dev.rubyonrails.org/ticket/5091 - the decsription is included
below).
I''ve noticed some posts to rails-core notifying the world of patches,
since there''s been no activity on said patch I thought I''d do the
same. Please let me know if this breaks protocol.
Cheers,
Ian White
--- patch summary
2006 Jun 25
1
Money library usage?
Hi,
I''m obviously doing something stupid, but I''m trying to figure out how
the Money library (http://dist.leetsoft.com/api/money/) is supposed to
work. I have a Product model and I want to have an attribute in my
model called "price" and I want it to accept Money objects.
So I have this in my Product model.
class Product < ActiveRecord::Base
composed_of :price,
2006 Apr 27
0
DRY validation
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,
A few months ago someone posted a message about specifying validates_*
constraints on a per-attribute basis. I just created a small plugin
that
allows you to do this.
Here''s an example from one of my models:
class Country < ActiveRecord::Base
attribute :name, :string do |a|
a.validates_length :within =>
2007 Mar 09
2
Blank fields getting validated
Hi,
I am not sure if this is already answered in this list. I couldn''t
find an answer. So I am posting the question.
I have multiple validations for a field. For example:
validates_presence_of :contact_email
validates_format_of :contact_email,
:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i,
:message => "is not a valid email
2007 Nov 03
3
Birthdate validation
Hello everyone,
I''m almost cracking my head trying to do this birthdate validation. It
turns out that I can only accept users with at least 18 years old and
I''m trying to validate it writing this code on my user.rb fil at app/
models
class User < ActiveRecord::Base
validates_presence_of :full_name
validates_presence_of :street_address
validates_presence_of :city
2006 Jul 22
3
refactoring commonly used aggregations
I have a number of models that use an aggregation to combine First Name,
Middle Initial and Last Name and they have been working fine. I am
looking to clean this up, DRY it if possible.
I have things like this in application.rb
class Clwholename
attr_reader :first_name, :middle_initial, :last_name
def initialize(first_name, middle_initial, last_name)
@first_name = first_name
2009 Sep 19
1
validations on a field
hi, i have a model with 2 validations on a field
example:
validates_presence_of :email
validates_length_of :email, :within => 6..100 #r@a.wk
validates_uniqueness_of :email
validates_format_of :email, :with =>
Authentication.email_regex
if i do the submit of form for a new object of the model with a blank
mail
i receive 4 errors.
In this case i want receive
2006 Apr 14
1
Validating Existing Models
I''ve got a user object which has quite a few attributes mapped to the
database. As of right now I''ve got some validations in the model like:
validates_presence_of :password, :message => "You must specify a valid
password."
validates_confirmation_of :password, :message => "Password doesn''t match
the confirmation."
validates_presence_of
2006 Feb 28
12
Examples for Money library ?
Can anybody share some examples of their Money implementation ?
I''m trying to setup a Model to use this library, but can''t seem to wrap my
head around how it is exactly supposed to work.
My Model (Foo) looks like:
===============
composed_of :commission, :class_name => "Money", :mapping => [
%w(commission_cents cents), %w(commission_currency currency) ]
Yet, in