Displaying 20 results from an estimated 10000 matches similar to: "composed_of and validates_presence_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
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
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 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
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|
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,
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 05
2
Serialized object behaves weird
Hi!
I got a class named EinsatzFilter which I serialized to session. Before
saving to session it works afterwards I keep getting the message:
"undefined method `to_s'' for #<Person:0x38c6ab8>". "Person" is a from
ActiveRecord::Base inherited class.
Code:
class EinsatzFilter
include ApplicationHelper
attr_reader :personen, :monat, :projekte, :kunde
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 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 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 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 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
2005 Dec 20
0
Using Aggregations in HTML forms?
I am slightly struggling to get a basic aggregation setup
For example I have a column in my database called "email" which stores
an email address. For various reasons I want the form on screen to be
like "<enter email name here>@domain.com", ie the domain part is already
fixed - the username is changeable
So I create a class called Email which picks the two pieces
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
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
2007 Feb 20
1
error message for record not found ?
I''m using backgroundrb for session management and deletion of visitor-entered information when a session is abandoned. The visitor can either click a button to end their session and remove their data, or backgroundrb will do it for them after 5 minutes of inactivity.
Everything''s working fine, I think. If the visitor explicitly logs out, then when the worker checks for their
2008 Feb 25
1
NoMethodError: undefined method `<=>' for :zip:Symbol
Long time programmer, but I just started learning RoR last week. I am
going through some examples in the book "Ruby on Rails: Up and
Running".
The example I am on had me add a table to the database that looks like
so:
CREATE TABLE people (
`id` int(11) NOT NULL auto_increment,
`type` varchar(20) default NULL,
`name` varchar(20) default NULL,
`email` varchar(30) default NULL,
2006 Jul 24
1
Newbie error: undefined local variable or method
When I add an item to the shopping cart, I get an error:
undefined local variable or method `cart_item'' for
#<#<Class:0x3715a78>:0x3715a48>
Session info says the cart being updated properly. I''m just not able
to output two variables:
<%= cart_item.quantity %> × <%= h(cart_item.title) %>
I did some research, and I can grasp that local
2006 Jul 19
5
Model Validation - with a twist
I''m stuck in a catch-22 type problem. I have an insert form for a table
that uses the validation in the model. i.e. When you click submit on the
form and haven''t filled in the required fields then you get the nice
rails error messages saying "field can not be blank". This works fine
until I introduce some more logic.
What I''m trying to do is to validate