我試圖通過使用回形針的ajax上傳圖像。回形針重複的網址錯誤
我使用qqfileuploader爲ajax的東西,它似乎沒有一個選項,我可以定義發佈請求的參數名稱。
從阿賈克斯後發送的參數是
qqfile=filename.jpg
所以在我的模型,我別名qqfile到照片
alias_attribute :qqfile, :photo has_attached_file :photo attr_accessible :title, :photo
當我上傳通過AJAX的文件時,我得到以下錯誤
Parameters: {"qqfile"=>"Penguins.jpg"} WARNING: Can't verify CSRF token authenticity Creating scope :page. Overwriting existing method User.page. User Load (1.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1 Creating scope :page. Overwriting existing method RoleUser.page. Creating scope :page. Overwriting existing method Role.page. Role Load (1.4ms) SELECT `roles`.* FROM `roles` INNER JOIN `role_users` ON `roles`.`id` = `role_users`.`role_id` WHERE `role_users`.`user_id` = 1 SQL (0.7ms) BEGIN Creating scope :page. Overwriting existing method Task.page. [paperclip] Duplicate URL for photo with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in Recipe class
我不知道,如果CSRF令牌將是一個問題,還有就是對網頁上的標記,S o也許我只需要發送,我想我可以得到它是一個JavaScript的變量?
但是,重複的URL的處理是什麼?我沒有正確的別名?由於某種原因,我可以不使用回形針對象嗎?
我的控制也很簡單
def create @recipe = Recipe.new(params[:recipe]) @recipe.author_id=current_user.id if @recipe.save return render :json => @recipe else return render :text => 'an error occured saving the recipe' end end
你能提供(全部)'has_attached_file'的確切調用嗎? – moritz 2012-01-04 14:10:04
@mosch,我添加了has_attached_file和attr_accessible,這只是我所知道的基礎知識。 – pedalpete 2012-01-04 14:29:02