开发者

Represent record associations in Rails

开发者 https://www.devze.com 2023-02-18 04:52 出处:网络
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.

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

精彩评论

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