Displaying 20 results from an estimated 300 matches similar to: "How to use validation with aggregation (composed_of)?"
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 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.
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 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
...
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|
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 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
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
2009 Nov 18
2
Composing Data from THREE models with Aggregation
Hello! I''m looking for assistance EXTENDING an example from the Agile
Web Development With Rails book: Composing Data with Aggregation (page
324).
I''m trying to map three columns to a single Ruby object. However,
unlike the example in the Agile Web Development book, the three
columns I want to map into one object come from THREE DIFFERENT
models.
I want to map the following
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 Jan 22
0
Validation on composed_of problem
I am having problems with this:
validates_presence_of :amount
validates_format_of :amount, :with => Money::PATTERN, :allow_nil =>
true
composed_of :amount, :class_name => Money, :mapping => [[:amount,
:to_s]]
The problem is when I use this field in a form, and the text is blank,
ActiveRecord gives me two errors:
"money is invalid"
"money
2006 Jan 30
1
Introduction & time_zone_select with mapped TimeZone question
I''m new to this list, I''m a student in History, Computerscience and a
bit of Philosophy from the Netherlands... I have started using rails a
few weeks ago, I did read the Agile Webdevelopment with Rails book, and
I generally started to love Rails for it''s sheer beauty and intelligent
structure...
However I came across something that puzzles me quite a bit. It''s
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
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
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,
2008 Jan 11
5
Missing methods
We have a custom implementation of the Mother Object idea. It''s inside
of a module, basically like this:
module Factory
%w(account friendship person invitation message asset email_address
birth).each do |klass|
eval <<-EOF
def self.create_#{klass}(attributes = {})
default_attributes = valid_#{klass}_attributes
#{klass.camelize}.create!
2006 Jun 17
5
STI versus Composition...or the headaches of one big table
Guys,
I have a relationship between model classes that I believe is best
represented by inheritance, but the likelihood that things will change
often is driving us to composition instead.
So, I have a class called Autos, and subclasses called Suvs, Minis,
Mids, Sports, for example.
We have been requested to avoid the STI approach to this, because of
fear of a quickly growing table with
2005 Apr 27
1
Ruby Shipping
To accompany the Payment library (http://payment.rufy.com/), I have
created the shipping library that connects APIs for various shippers
like UPS and FedEx. It is available as a ruby gem:
gem install shipping
or from rubyforge
http://rubyforge.org/projects/shipping
There is going to be some data that will persist for all shipments. For
example, you will not want to repeat the fedex account
2008 Jan 23
1
Making Parents object attributes available
Hello,
I have a class Person
class Persoon < ActiveRecord::Base
set_table_name "Persoon"
set_primary_key "p_persoon"
has_many :adres, :class_name => "Adres"
composed_of :name, :class_name => Name, :mapping => [ [:naam,:naam],
[:voornaam,:voornaam], [:voornaam2,:voornaam2],
[:persnickname,:persnickname], [:perssortname,:perssortname] ]
def
2019 Feb 25
2
funnel shift, select, and poison
On 2/25/2019 12:28 PM, John Regehr via llvm-dev wrote:
> Poison has to propagate through calls and loads/stores, or else
> basically nothing works.
Consider this:
%v0 = call i32 @foo(poison) nounwind/readnone
store i32 %v0, i32* %valid_address
If we assume that poison propagates through calls, we could then
optimize this to
%v0 = poison
store poison, i32* %valid_address
If