2013-05-06 67 views
0

我想使用jQuery的阻力,並通過以下這個例子的Rails:爲什麼這個奇怪的錯誤

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是被在視圖中使用。

感謝您的任何幫助

+1

'property_files_path'是路線form_for'標籤生成爲表單的默認動作。錯誤清楚地指出錯誤來自哪條線。 – sevenseacat 2013-05-06 05:21:30

+1

你的routes.rb是怎麼樣的? – Mattherick 2013-05-06 05:21:36

回答

1

它被窗體生成器調用。爲此,您可能需要添加:

resources :property_files 

......到您的路線。

如果你不想形式默認爲足智多謀的路線,你可以通過將url選項form_for,例如指定上傳操作自己的路:

<% form_for @object_new, {:url => "/property_files/upload", ... } %> 
相關問題