我有一个模型'画廊',它与'Exhbition Images'(并与belongs_to相反)具有'has_many'关系。访问属于另一个模型的模型
我想通过图库模型显示与每个图库相关的图像。但是我遇到的错误
undefined method `exhibition_images' for #<Gallery::ActiveRecord_Relation:0x00000108159dd0>
当我试图实现这行代码
gallery index:
<%= @gallery.exhibition_images.each do |exhibition_image| %>
<%= exhibition_image.title %>
<% end %>
我相信这是很简单的,我失去了一些东西明显。
画廊控制器
def index
@gallery = Gallery.all
end
画廊模式
class Gallery < ActiveRecord::Base
extend FriendlyId
friendly_id :title, use: :slugged
belongs_to :guide
has_many :exhibition_images
accepts_nested_attributes_for :exhibition_images
end
展览图片
class ExhibitionImage < ActiveRecord::Base
belongs_to :gallery
has_attached_file :image, styles: { small: "100x100", guide: "500x500" }
validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
end
SCHEMA
create_table "exhibition_images", force: true do |t|
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.integer "gallery_id"
t.datetime "created_at"
t.datetime "updated_at"
末
create_table "galleries", force: true do |t|
t.string "title"
t.string "slug"
t.integer "guide_id"
t.datetime "created_at"
t.datetime "updated_at"
end