我正在通过创建一个简单的图像板来学习Rails。我希望用户能够将图像上传到服务器,然后我将能够为他们提供服务。使用Rails,Paperclip和Backbone上传文件
我正在使用rails-backbone和paperclip。
下面是相关的部分:
应用程序/模型/ image.rb
class Image < ActiveRecord::Base
attr_accessible :url
attr_accessible :data
has_attached_file :data, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end
应用程序/资产/ Java脚本/骨干网/模板/图像/ submit.jst.ejs
<form id="new-image" name="image" data-remote="true" enctype="multipart/form-data">
<div class="field">
<label for="data"> image:</label>
<input type="file" name="data" id="data">
</div>
<div class="actions">
<input type="submit" value="Create Image" />
</div>
</form>
app/controllers/images_controller.rb
def create
@image = Image.new(params[:image])
respond_to do |format|
if @image.save
format.html { redirect_to @image, notice: 'Image was successfully created.' }
format.json { render json: @image, status: :created, location: @image }
else
format.html { render action: "new" }
format.json { render json: @image.errors, status: :unprocessable_entity }
end
end
end
我也跑这种迁移:
class AddAttachmentDataToImages < ActiveRecord::Migration
def self.up
add_attachment :images, :data
end
def self.down
remove_attachment :images, :data
end
end
在试图保存一个名为“fruits.png”,我得到这个输出在控制台文件:
Started POST "/images" for 127.0.0.1 at 2012-10-31 00:55:07 -0700
Processing by ImagesController#create as JSON
Parameters: {"image"=>{"url"=>nil, "data"=>"C:\\fakepath\\fruits.png"}}
Completed 500 Internal Server Error in 2ms
Paperclip::AdapterRegistry::NoHandlerError (No handler found for "C:\\fakepath\\fruits.png"):
app/controllers/images_controller.rb:16:in `new'
app/controllers/images_controller.rb:16:in `create'
任何帮助,将不胜感激!谢谢!
可能的重复:http://stackoverflow.com/questions/10033425/paperclip-exception-paperclipadapterregistrynohandlererror – prusswan
似乎是相同的错误,除非它看起来像解决方案是告诉表单窗体是多部分。我的表单的enctype =“multipart/form-data”,所以我不认为这是问题。 –
另一个:http://stackoverflow.com/questions/12336081/nohandlererror-with-rails3-and-paperclip?lq=1假设您的问题不是太本地化,检查您的回形针设置通过运行其他集成它的项目,如https://github.com/tors/jquery-fileupload-rails-paperclip-example – prusswan