我正在使用回形针和导轨。我按照本教程: Multiple File Uploads with Paperclip & Rails 3 (Screencast)
我有一个画廊模型,有很多galleryphotos。
我没有在视图中链接到原始图像,而是在photoimage中创建了一个show方法,但是我收到了以下错误:
undefined method `galleryphoto_path' for #<#<Class:0x007f40a0000c20>:0x00000005385d60>
这是我的代码:
<% for asset in gallery.galleryphotos %>
<%= link_to image_tag(asset.photo.url(:thumb)), url_for(asset) %>
<% end %>
这是我的galleryphoto控制器:
class GalleryphotosController < ApplicationController
load_and_authorize_resource
def show
@gallery = Gallery.find(params[:gallery_id])
@galleyphoto = @gallery.galleyphotos.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @gallery }
end
end
end
以下是我的路线:
resources :galleries do
resources :galleryphotos
end
任何想法如何解决这个问题?
答案 0 :(得分:2)
url_for
帮助程序找不到Galleryphoto
模型的路由,因为它取决于Gallery
模型。它在路由中声明为嵌套资源,因此如果网址中没有Galleryphoto
,则Gallery
不存在。
要解决此问题,请执行以下任一操作:
<%= link_to image_tag(asset.photo.url(:thumb)), url_for(gallery, asset) %>
或
<%= link_to image_tag(asset.photo.url(:thumb)), gallery_galleryphoto_path(gallery, asset) %>