-1

我正在学习本教程并遇到了困难。

我通过调用获得路由错误http://localhost:3000/home 也许我只是调用了错误的页面。如果有人帮助我,我将不胜感激。


Hier 是我的 routes.rb:

Try::Application.routes.draw do
 resources :uploads
 root :to => "home#index"
end


uploads_controller.rb:

class UploadsController < ApplicationController
  def home
  end

  def index
  end


  def create
    @upload = Upload.new(params[:upload])
    if @upload.save
      render :json => { :pic_path => @upload.picture.url.to_s , :name => @upload.picture.instance.attributes["picture_file_name"] }, :content_type => 'text/html'
    else
      render :json => { :result => 'error'}, :content_type => 'text/html'
    end
  end

end

和意见/主页/index.html.erb:

<%= stylesheet_link_tag('jquery.fileupload-ui') %>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
<%= javascript_include_tag 'jquery.fileupload', 'jquery.fileupload-ui' %>

<script type="text/javascript" charset="utf-8"> 
   $(function () {
  $('.upload').fileUploadUI({
        uploadTable: $('.upload_files'),
        downloadTable: $('.download_files'),
        buildUploadRow: function (files, index) {
            var file = files[index];
            return $('<tr><td>' + file.name + '<\/td>' +
                    '<td class="file_upload_progress"><div><\/div><\/td>' +
                    '<td class="file_upload_cancel">' +
                    '<button class="ui-state-default ui-corner-all" title="Cancel">' +
                    '<span class="ui-icon ui-icon-cancel">Cancel<\/span>' +
                    '<\/button><\/td><\/tr>');
        },
        buildDownloadRow: function (file) {
            return $('<tr><td><img alt="Photo" width="40" height="40" src="' + file.pic_path + '">' + file.name + '<\/td><\/tr>');
        },
    });
});
</script>

<div class="files"> 
<%= form_for @upload, :html => { :class => "upload", :multipart => true } do |f| %>
  <%= f.file_field :picture %>
  <div>Upload files</div>
<% end %>

<table class="upload_files"></table>
<table class="download_files"></table>
</div>

home_controller.rb:

class HomeController < ApplicationController
def index
  @upload  = Upload.new
end
end
4

2 回答 2

1

您的路线文件说根路径,即“/”将指向 home#index。

'/home' 没有路由 建议你添加:

match '/home' => 'uploads#home'
于 2012-10-18T08:21:19.570 回答
-1

当您在路由文件中说 root :to => "home#index" 时,这意味着主控制器索引操作

您的视图文件结构也需要修改为views/controller_name/index.html.erb:

于 2012-10-18T08:05:44.933 回答