Hi All,
I can't figure out how to call the to_label method on a second order
association (AS 2.3, ROR 2.38). I have "Articles" that belongs to
"Rooms" that belongs to "Floors". I want to show "Floors.description -
Rooms.description" as the label for Rooms inside Articles, and I also
want to use that label inside a select in the update/create for
Articles, the problem is that I get instead the ID of Floors, not the
outcome of the to_label method for the Floor object. I tried to call
explicitlily the to_label method on the associated object but I get a
nil class error.
In the end I'm giving up, whatever I do I cannot find a way to get it.
Here follows the details.
class Article < ActiveRecord::Base
belongs_to :room
end
class Room < ActiveRecord::Base
belongs_to :floor
def to_label
"#{floor} - #{description}" // calling explicitily floor.to_label
gives a nil class error
end
end
class Floor < ActiveRecord :: Base
has_many :rooms
def to_label
"#description"
end
end
Thanks
davide
--
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