0

我正在使用回形针和导轨。我遵循了本教程: 使用 Paperclip 和 Rails 3 上传多个文件(屏幕截图)

我有一个画廊模型,里面有很多画廊照片。

我没有链接到视图中的原始图像,而是在 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 %>

这是我的画廊照片控制器:

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

任何想法如何解决这一问题?

4

1 回答 1

2

助手将url_for找不到模型的路线,Galleryphoto因为它取决于Gallery模型。它在路由中被声明为嵌套资源,因此在 url 中Galleryphoto没有 a 就不存在 a 。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) %>
于 2012-07-06T12:55:29.210 回答