我想要參考buildings/index.html.erb
中的圖像。我有:從另一個型號中選擇一個型號
class BuildingsController < ApplicationController
def index
@buildings = Building.all
@images = @buildings.images.all
end
end
class Building < ActiveRecord::Base
has_many :images
end
class Image < ActiveRecord::Base
belongs_to :building
end
建築/ index.html.erb:
<% @buildings.each do |building| %>
<% if @buildings.images.any? %>
<% @buildings.images.name %>
<% end %>
<% end %>
我得到以下錯誤:undefined method images for <Array:0x000001109b4680>