我有两个模型Location和LocationType。Rails,CamalCase Model Name检索相关记录?
class LocationType < ActiveRecord::Base
has_many :locations
end
class Location < ActiveRecord::Base
belongs_to :location_type
end
在我的选址模型我有外键:location_type_id
在我看来,我试着拨打:
@location.location_type.name
,但我得到一个错误:
未定义方法`name'为零:NilClass
如何获得显示location_type相关记录的视图?
你的数据库看起来像什么?你可以给我们@location的价值吗? – 2011-06-08 03:24:36
@location有:name =“TEST1”,:map_url =“http:// ....”,并且location_type_id = 1 – Mike 2011-06-08 03:53:29