search for: composed_of

Displaying 20 results from an estimated 45 matches for "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)...
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 find any documentation for) validation of the value objects. For example, given the following: class Message < ActiveRecord::Base composed_of :sender, :class_name =&gt...
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 script/console, I''m unable to get the correct behaviour (at least I think), from the library. =============== >> t = Foo.new(:commission => 34...
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 P...
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 =&gt...
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 g...
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 t...
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 sim...
2006 Mar 03
0
unused composed_of bits
...ture, units = "F" ) unless valid_units?(units) units = "F" end @temp = temperature = ((10 * temperature).to_f.round)/10.0 @units = units.upcase end def to_c convert_to("C") end ... etc. So in my app model: class Profile < ActiveRecord::Base composed_of :temperature, :class_name => Temperature, :mapping => [ :temp, :temp ] def before_save self.temperature.to_f! end The table corresponding to Profile has a column named temp. What happens to the units? Is it merely ignored? When I navigate to /profiles/new I get...
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 can''t be blank" I want only "money can''t be blank&qu...
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| Money.new(s) }, :mapping => [:price, :value] end class Money attr_reader :value def initialize(string) @value = BigDecimal(string.sub(/,/, ''.''))...
2006 Mar 16
5
TimeZone, TZInfo, daylight savings, and composed_of
...ocumentation 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 ... composed_of :time_zone, :class_name => TimeZone, :mapping => %w(time_zone name) end There also seems to be a TZInfo library that supports daylight savings. It seems strange that the TimeZone class in rails doesn''t support daylight savings as Basecamp from 37Signals uses timezones and I'...
2006 May 08
2
Creating a "Foo has_many bars" association where bar isn''t a model.
Hi Let''s say we have model Foo. Each Foo instance can have several bars. Those bars are primitive, so they shouldn''t be models. For example, Foo might be a type of convention, and the bars might be years the convention was held in. Naively, we would have a conventions_years date, and put: has_many :years inside class Convention. But then we''d get an error, since for
2009 Nov 18
2
Composing Data from THREE models with Aggregation
...opment book, I couldn''t get :grade.grade_abbr and strand.strand_abbr to work. The code below was the best that I could come up with but it shows grade_id and strand_id. Does anyone have a suggestion for how to make this work or for a new strategy? class Standard < ActiveRecord::Base composed_of :full_standard, :mapping => [ %w[grade_id grade_id], %w[strand_id strand_id] %w[number number] ] class FullStandard < ActiveRecord::Base attr_reader :grade_id, :strand_id, :number def i...
2006 Jan 30
1
Introduction & time_zone_select with mapped TimeZone question
...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 how to add a time_zone_select form field using a composed_of class with mapped utc_offset and name fields... In my form I have: <%= time_zone_select(''user'',''time_zone'') %> In my user-class I have: composed_of :time_zone, :class_name => ''TimeZone'', :mapping => [%w(time_zone_name name) %w(ti...
2006 Jul 22
3
refactoring commonly used aggregations
...ze(first_name, middle_initial, last_name) @first_name = first_name @middle_initial = middle_initial @last_name = last_name end def to_s [ @first_name, @middle_initial, @last_name ].compact.join(" ") end end and then in whichever model I need to use this, I have... composed_of :clwholename, :class_name => Clwholename, :mapping => [[ :first_name, :first_name ], [ :middle_initial, :middle_initial ], [ :last_name, :last_name ] ] which is repeated in a number of models. I ran into a snag when trying to use RAV (which is very...
2006 Jul 14
1
auto completion with composite field
How can auto completion be done for a composite field ? Concrete problem : Suppose the class Person with reference to a City object. The City has a name and a postal code. When entering a Person I want to enter the city in one text field that shows a composition of the city name and the postal : "city (postal)". And this with auto complete (and should afterwards be linked to the
2006 Jun 25
1
Money library usage?
...gure 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, :class_name => ''Money'' end >From what I can tell, I should be able to do: p = Product.new p.price = Money.new(1999) and have the price return a Money object? I can''t get this to work. What am I doing wrong? Is this how Money is supposed to work? Tha...
2006 Jun 17
5
STI versus Composition...or the headaches of one big table
...n, but having a Autos table with an suv_id, mini_id, mid_id, and sports_id (for all possible combos) seems like really bad design. I suppose I could have the Autos table have a sub_type_id and sub_type column, and somehow use this to map. However, I''m unsure how to go about this...composed_of doesn''t seem to be designed with this situation in mind. Any insight or suggestions you may provide will be very welcome. Thanks! B.A. -- B.A. Baracus: I thought you weren''t crazy no more? Murdock: Only on paper. -- Posted with http://DevLists.com. Sign up and save your mailb...
2006 Jul 26
4
Dropdown with concatenated columns.
What is the best way to create a drop down where the viewable text in a concatenation of 2 or more columns? For instance, I hane a lookup table with these columns. Model FOO columns: id , name, phone In my drop select tag, I''d like the user to see: "name1 phone1" "name2 phone2" etc.. I know I can do this using find_by_sql . .. But, isn''t there a more