2011-10-07 88 views
0

我的模型:(使用MySQL和我有字段:id, name, image, remote_image_url, created_at, updated_at滑軌+ SWFUpload的=

require 'mime/types' 
class Avatar < ActiveRecord::Base    

has_attached_file :image, :styles => { :small => "150x150>", :large=> "320x240>" } 

def swfupload_file=(data) 
    data.content_type = MIME::Types.type_for(data.original_filename) 
    self.image = data 
    end 

end 

控制器

def upload 
    if params[:Filedata] 
     @avatar = Avatar.new(:swf_uploaded_data => params[:Filedata]) 
     if @avatar.save 
     render :partial => 'photo', :object => @avatar 
     else 
     render :text => "error" 
     end 
    else 
     @avatar = Avatar.new params[:image] 
     if @avatar.save 
     flash[:notice] = 'Your photo has been uploaded!' 
     redirect_to photos_path 
     else 
     render :action => :new 
     end 
    end 
    end 

Index.html.erb

<head> 
    <title>.test.</title> 
    <%=swfupload_head %> 
</head> 
<br/><br/> 
<%=swfupload :controller=>'test',:action=>'upload'%> 

=== ================================

我有

Processing TestController#upload (for 127.0.0.1 at 2011-10-07 11:46:29) [POST] 
    Parameters: {"request_forgery_protection_token"=>"T2KBI+Wk16fhYHSxUh5HRH72LTIdK//327yuuRkWrqs=", "Filename"=>"bg-body2.jpg", "_test_for_projects_session"=>"BAh7BzoPc2Vzc2lvbl9pZCIlNmU3MGQxMzYzOWI5ZWNmYTk5YzQ4YTU3MWM2YzM3ZDk6EF9jc3JmX3Rva2VuIjFUMktCSStXazE2ZmhZSFN4VWg1SFJINzJMVElkSy8vMzI3eXV1UmtXcnFzPQ==--1084bd5f8d5dd4378a3a40a4e35559875881b6fd", "amp"=>nil, "authenticity_token"=>"T2KBI+Wk16fhYHSxUh5HRH72LTIdK//327yuuRkWrqs=", "Upload"=>"Submit Query", "Filedata"=>#<File:/tmp/RackMultipart20111007-7833-1ryc6s-0>} 
    SQL (1.9ms) SHOW TABLES 
    Avatar Columns (1.0ms) SHOW FIELDS FROM `avatars` 
    SQL (1.7ms) SHOW TABLES 
    Avatar Columns (1.0ms) SHOW FIELDS FROM `avatars` 

NoMethodError (undefined method `has_attached_file' for #<Class:0x7ffdca03a7a8>): 
    app/models/avatar.rb:35 
    app/controllers/test_controller.rb:6:in `upload' 

Rendered rescues/_trace (78.6ms) 
Rendered rescues/_request_and_response (0.4ms) 
Rendering rescues/layout (internal_server_error) 

======

問題:爲什麼NoMethodError?爲什麼數據沒有嵌入數據庫?

UPD:

我刪除模型attached_file ...現在數據插入但..在這樣的觀點:

Processing TestController#upload (for 127.0.0.1 at 2011-10-07 12:12:31) [POST] 
    Parameters: {"request_forgery_protection_token"=>"T2KBI+Wk16fhYHSxUh5HRH72LTIdK//327yuuRkWrqs=", "Filename"=>"Firefox_wallpaper.png", "_test_for_projects_session"=>"BAh7BzoPc2Vzc2lvbl9pZCIlNmU3MGQxMzYzOWI5ZWNmYTk5YzQ4YTU3MWM2YzM3ZDk6EF9jc3JmX3Rva2VuIjFUMktCSStXazE2ZmhZSFN4VWg1SFJINzJMVElkSy8vMzI3eXV1UmtXcnFzPQ==--1084bd5f8d5dd4378a3a40a4e35559875881b6fd", "amp"=>nil, "authenticity_token"=>"T2KBI+Wk16fhYHSxUh5HRH72LTIdK//327yuuRkWrqs=", "Upload"=>"Submit Query", "Filedata"=>#<File:/tmp/RackMultipart20111007-7833-1jylds4-0>} 
    Avatar Columns (1.1ms) SHOW FIELDS FROM `avatars` 
    SQL (0.6ms) BEGIN 
    Avatar Create (0.8ms) INSERT INTO `avatars` (`name`, `remote_image_url`, `created_at`, `updated_at`, `image`) VALUES('', '', '2011-10-07 09:12:31', '2011-10-07 09:12:31', '--- !ruby/object:File {}\n\n') 
+0

我看到'has_attached_file',所以推測你使用的是Paperclip。您的'Gemfile'中是否有Paperclip,並且您是否使用'bundle install'安裝了捆綁包? –

+0

SWF_uploader_fu僅適用於回形針?如果我刪除has_attacged_file?請在帖子中查看我的更新! –

+0

我不明白你的問題。我不知道「SWF_uploader_fu」是什麼,Google的搜索結果爲零。如果您使用的是特定的寶石或教程,應該鏈接到它。 –

回答