undefined method `url' for #<GalleryPhoto:0x007f80c05a4ba8>
10: <%= @gallery.date %>
11: </p>
12:
13: <%= @gallery.gallery_photos.first.url %>
14:
15:
16: <%= link_to 'Edit', edit_gallery_path(@gallery) %>
Run Code Online (Sandbox Code Playgroud)
我正在尝试在rails应用程序中创建相册系统,在该应用程序中创建相册并通过回形针将图像上传到相册.我无法使用.url方法在我的显示页面上工作以显示图像.它的设置方式是这样的:
画廊模型(有很多gallery_photos)
GalleryPhotos模型(belongs_to gallery)
画廊展示:
<p id="notice"><%= notice %></p>
<p>
<b>Gallery name:</b>
<%= @gallery.gallery_name %>
</p>
<p>
<b>Date:</b>
<%= @gallery.date %>
</p>
<%= @gallery.gallery_photos.first.url %>
<%= link_to 'Edit', edit_gallery_path(@gallery) %> |
<%= link_to 'Back', galleries_path %>
Run Code Online (Sandbox Code Playgroud)
画廊模型
class Gallery < ActiveRecord::Base
attr_accessible :date, :gallery_name, :gallery_photos_attributes
has_many :gallery_photos, :dependent => :destroy
accepts_nested_attributes_for :gallery_photos
end
Run Code Online (Sandbox Code Playgroud)
gallery_photo模型
class GalleryPhoto …Run Code Online (Sandbox Code Playgroud)