From: Eduardo Blumenfeld on 21 Jun 2010 00:59 I have: ------------------------ class Customer < ActiveRecord::Base belongs_to :Customer_Type end class Customer_Type < ActiveRecord::Base has_many :Customers end ------------------------ Is there a built-in way to auto populate customer_type_id based on the "Human name" of the Customer_Type_ID? ------------------------ c = Customer.new( :name => "John Doe", :customer_type_name => "Wholesale" ) ------------------------ # c[:Customer_Type_ID] == 10 (if 10 is the id for the "Wholesale" customer type) -- Posted via http://www.ruby-forum.com/.
From: Ammar Ali on 21 Jun 2010 04:09 On Mon, Jun 21, 2010 at 7:59 AM, Eduardo Blumenfeld <eblumenfeld(a)e-mbinfosys.com> wrote: > I have: > > ------------------------ > class Customer < ActiveRecord::Base > Â belongs_to :Customer_Type > end > > class Customer_Type < ActiveRecord::Base > Â has_many :Customers > end > > ------------------------ > > Is there a built-in way to auto populate customer_type_id > based on the "Human name" of the Customer_Type_ID? > > ------------------------ > c = Customer.new( :name => "John Doe", :customer_type_name => > "Wholesale" ) > ------------------------ > # c[:Customer_Type_ID] == 10 Â (if 10 is the id for the "Wholesale" > customer type) > -- > Posted via http://www.ruby-forum.com/. > > ActiveRecord questions are better placed on the Rails mailing list, but here's a hint: type = CustomerType.find_by_name("Wholesale") Ammar
|
Pages: 1 Prev: Writing files in Windows in correct enc. for batch scripts Next: Closures in Ruby |