私はこのチュートリアルに従っていましたが、困難に遭遇しました。
間違っ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
および views/home/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