rubyonrailsin

A Ruby and Rails talk

Tuesday, March 9, 2010


[Rails] Re: Noob issue with virtual attributes

by rubyonrailsin 0 comments



Share this post:
Design Float
StumbleUpon
Reddit

Frederick Cheung wrote:
> If you have a has_many you can do tips.build(...) but with belongs_to
> and has_one you need to call build_tip instead
>
> Fred

Thanks Fred, it works better now. But an have another issue. Now the
data are stored in the database but the column city_it in the table tips
is nil.
Do i have the set it the setter like this?

def tip_attribute=(attribute)
attribute[:city_id] = self.id
build_tip(attribute)
end


Tip model:
class Tip < ActiveRecord::Base
attr_accessible :min,:max,:city_id

has_one :city

validates_numericality_of :min, :only_integer => true
validates_numericality_of :max, :only_integer => true
end


It does work if I do this, but is it the correct way to do it? should it
be filled automaticly by active record?

Greg
--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive