I am getting an internal server error when I am attempting to upload images in the Ruby app I am working on. I know what the issue is itself, however I am not entirely sure how to fix it. As of now this is how the app works:
User visits page, is allowed to upload images and then the handling of the images will be done after upload. Therefore I am creating a new Gallery instance when the user visits the page (Galleries hold one or many Pictures). The issue is in my gallery controller where I am attempting to create the follwing:
def index
@gallery = Gallery.create
@picture = @gallery.pictures.build
respond_to do |format|
format.html # index.html.erb
format.json { render json: @galleries }
end
end
Annddd the error that follows when running "localhost:3000/galleries/"
Completed 500 Internal Server Error in 148ms
ActionView::Template::Error (undefined method `gallery_pictures_path' for #<#<Class:0x000001023d8b98>:0x00000102383670>):
3: <%= javascript_include_tag 'jquery.fileupload-ui.js' %>
4:
5:
6: <%= form_for [@gallery, @picture], :html => { :multipart => true, :id => "fileupload" } do |f| %>
7:
8: <div>
9: <div class=" fileupload-buttonbar">
app/views/galleries/index.html.erb:6:in `_app_views_galleries_index_html_erb__2795478836341012416_2164674980'
app/controllers/galleries_controller.rb:8:in `index'
The project itself is on GitHub here: https://github.com/dflynn15/UploaderTest
The issue is either with my understanding of Gallery.create and how a new instance is created (I know the risk of orphan instances running around but I am going to implement a expiration date after I get this uploading issue fixed), or my understanding of how Pictures and Gallery are connected disallowing @gallery.pictures to be an invalid path.
Thanks for any help!
Try this in routes.rb
resources :galleries, :shallow => true do
resources :pictures
end