I am using paperclip and rails. I followed this tutorial:
Multiple File Uploads with Paperclip & Rails 3 (Screencast)
I have a gallery model that has many galleryphotos.
Instead of linking to the original image in my view, I created a show method in photoimage, but I get the the following error:
undefined method `galleryphoto_path' for #<#<Class:0x007f40a0000c20>:0x00000005385d60>
Here is my code:
<% for asset in gallery.galleryphotos %>
<%= link_to image_tag(asset.photo.url(:thumb)), url_for(asset) %>
<% end %>
Here is my galleryphoto controller:
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
Here are my routes for these:
resources :galleries do
resources :galleryphotos
end
Any ideas how to fix this?
The
url_forhelper will not find a route for theGalleryphotomodel because it depends on theGallerymodel. It is declared in the routes as a nested resource, so aGalleryphotodoes not exist without aGalleryin the url.To fix this do any of the following:
or