图像上载内部服务器错误Ruby

时间:2012-07-03 14:13:59

标签: ruby-on-rails carrierwave internal-server-error

当我尝试在我正在处理的Ruby应用程序中上传图像时,我收到内部服务器错误。我知道问题本身是什么,但我不完全确定如何解决它。截至目前,这是应用程序的工作方式:

用户访问页面,允许上传图像,然后上传后处理图像。因此,当用户访问页面时,我正在创建一个新的Gallery实例(Galleries包含一个或多个图片)。问题出在我的画廊控制器中,我试图创建以下内容:

    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

运行“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'

项目本身在GitHub上:https://github.com/dflynn15/UploaderTest

问题在于我对Gallery.create的理解以及如何创建新实例(我知道孤立实例运行的风险,但我将在修复此上传问题后实现过期日期),或者我对图片和图库如何连接的理解不允许@ gallery.pictures成为无效的道路。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

在routes.rb

中试试
resources :galleries, :shallow => true do
    resources :pictures
end