私のモデル;
class Appartment < ActiveRecord::Base
belongs_to :region
end
class Region < ActiveRecord::Base
belongs_to :country
has_many :appartments
has_many :houses
end
マンション管理人(一部)
クラス AppartmentsController < ApplicationController
def index
add_breadcrumb "homepage", :root_path
@country = Country.find(params[:country_id])
@regions = @country.regions
@appartments = Appartment.all
end
アパートのインデックス ビューで、正しい URL リンクを取得するために各ループを作成しました。
.span9
%article.chat.t_xs
.article-base
#container
- @regions.each do |region|
- @appartments.where(region_id: region.id).each do |appartment|
.item{:class => appartment.features_to_html_class }
%section
.span4
%h2 #{link_to appartment.name, country_region_appartment_path(@country, region, appartment)}
%ul.stars.floatstars
%li.yellowstars{:style => "width: #{appartment.avg_rating * 25}px !important;"}
%footer
%br
%p
= raw truncate(appartment.property_description, :length => 250, :omission => '...')
#{link_to "meer", country_region_appartment_path(@country, region, appartment)}
「Array:Class のメソッド `where' が未定義です」というエラー メッセージが表示されます。
ciao..remco