我已经按照他们的 github 页面上的回形针教程进行操作。
我创建了一个迁移
rails g paperclip blog picture
在我的 blog.rb (模型)
has_attached_file :picture, :styles => { :medium => "600x400>", :thumb => "260x180>" }
attr_accessible :title, :body, :picture
在我的控制器中
def create
@blog = Blog.new( params[:blog] )
respond_to
等等....
在我的 _form.html
<%= form_for @blog, :html => { :multipart => true, :class => 'form-horizontal' } do |f| %>
现在,如果我尝试创建一个没有图像的新博客,它会像往常一样创建。但是,如果我尝试用图片创建一个,它不会被创建,我会被重定向到new_blogs_path
. 重定向很好,考虑到我有一个 if @blog.save respond_to
,所以发生的一切就是它似乎没有被保存。
有人有想法吗?