开发者

Represent record associations in Rails

All,

How can I show record association in the "view" part of the MVC using Rails? Ex. I have a class for Building which would have many apartments each with a single unique apartment number.

Since I am new to Rails, I wanted t开发者_StackOverflow中文版o understand what is generally the UI structure to represent such associations on the UI side.


I am still not clear, this is how your models would look

class Apartment < ActiveRecord::Base
 belongs_to :building
end

class Building < ActiveRecord::Base
 has_many :apartments
end

In your routes.rb you may want to have the following

resources :building do
 resources :apartments
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜