0

我正在尝试按照此示例使用 jquery 拖放上传器

https://github.com/jalagrange/bootstrap_uploader

我的观点:

   <%= form_for @object_new, :html => { :multipart => true, :id => "fileupload"  } do |f| %>
        <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
        <div class="row fileupload-buttonbar">
          <div class="span7">
            <!-- The fileinput-button span is used to style the file input field as button -->
                <span class="btn btn-success fileinput-button">
                    <i class="icon-plus icon-white"></i>
                    <span>Add files...</span>
                  <%= f.file_field :path, :multiple => true %>
                </span>
            <button type="submit" class="btn btn-primary start">
              <i class="icon-upload icon-white"></i>
              <span>Start upload</span>
            </button>
            <button type="reset" class="btn btn-warning cancel">
              <i class="icon-ban-circle icon-white"></i>
              <span>Cancel upload</span>
            </button>
            <button type="button" class="btn btn-danger delete">
              <i class="icon-trash icon-white"></i>
              <span>Delete</span>
            </button>
            <input type="checkbox" class="toggle">
          </div>
          <div class="span5">
            <!-- The global progress bar -->
            <div class="progress progress-success progress-striped active fade">
              <div class="bar" style="width:0%;"></div>
            </div>
          </div>
        </div>
        <!-- The loading indicator is shown during image processing -->
        <div class="fileupload-loading"></div>
        <br>
        <!-- The table listing the files available for upload/download -->
        <table class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody>
        </table>
    <% end %>

控制器:

 def upload
       @object_new= Property::File.new

  end

模型:

class Property::File < ActiveRecord::Base
  attr_accessible :date, :description, :location, :name, :time ,:path
end

架构:

  create_table "property_files", :force => true do |t|
    t.string   "name"
    t.string   "description"
    t.string   "date"
    t.datetime "time"
    t.string   "location"
    t.datetime "created_at",  :null => false
    t.datetime "updated_at",  :null => false
    t.string   "path"
  end

路线.rb

  root :to => "property#home"  
  get "property/home"
  get "property/upload"

当我运行我的视图时,我收到了这个错误:

NoMethodError in Property#upload

Showing C:/myproject/app/views/property/upload.html.erb where line #71 raised:

undefined method `property_files_path' for #<#<Class:0x563d3a8>:0x563b5a8>
Extracted source (around line #71):

68:     </div><!--/span-->
69:     <div class="span9">
70: 
71:     <%= form_for @object_new, :html => { :multipart => true, :id => "fileupload"  } do |f| %>
72:         <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
73:         <div class="row fileupload-buttonbar">
74:           <div class="span7">
Rails.root: C:/myproject

我不明白在哪里property_files_path使用。

谢谢你的帮助

4

1 回答 1

1

它被表单生成器调用。为此,您可能需要添加:

resources :property_files

...到你的路线。

如果您不希望表单默认为资源丰富的路由,您可以通过将url选项传递给 来指定您自己的上传操作路径form_for,例如:

<% form_for @object_new, {:url => "/property_files/upload", ... } %>
于 2013-05-06T05:21:49.720 回答