我试图通过以下示例
来使用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
的routes.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
的位置。
感谢您的帮助
答案 0 :(得分:1)
它由表单生成器调用。为此,你可能想要添加:
resources :property_files
...到你的路线。
如果您不希望表单默认为资源丰富的路由,您可以通过将url
选项传递给form_for
来指定上传操作的路径,例如:
<% form_for @object_new, {:url => "/property_files/upload", ... } %>