使用 Paperclip 时 ActiveAdmin 不上传图像
我已遵循所有指南和答案,所有内容都显示正确,但实际上传并未发生:(
这是我的 ActiveAdmin 中的:
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs do
f.input :name
f.input :image, :multipart => true
end
end
这是我的模型中的:
has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :path => ":rails_root/app/assets/images/article_images/:id/:style_:basename.:extension"
I'我也尝试过没有路径,但没有成功
这是我的迁移: 。
class AddAttachmentImageToArticle < ActiveRecord::Migration
def self.up
add_column :articles, :image_file_name, :string
add_column :articles, :image_content_type, :string
add_column :articles, :image_file_size, :integer
add_column :articles, :image_updated_at, :datetime
end
def self.down
remove_column :articles, :image_file_name
remove_column :articles, :image_content_type
remove_column :articles, :image_file_size
remove_column :articles, :image_updated_at
end
end
I've followed all guides and answers, and everything displays correctly, but the actual upload doesn't happen :(
Here's in my ActiveAdmin:
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs do
f.input :name
f.input :image, :multipart => true
end
end
Here's in my model:
has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :path => ":rails_root/app/assets/images/article_images/:id/:style_:basename.:extension"
I've tried without a path also, didn't work.
Here's my migration:
class AddAttachmentImageToArticle < ActiveRecord::Migration
def self.up
add_column :articles, :image_file_name, :string
add_column :articles, :image_content_type, :string
add_column :articles, :image_file_size, :integer
add_column :articles, :image_updated_at, :datetime
end
def self.down
remove_column :articles, :image_file_name
remove_column :articles, :image_content_type
remove_column :articles, :image_file_size
remove_column :articles, :image_updated_at
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是该死的 attr_accessible 没有 :image
The problem was the damn attr_accessible not having :image
为了完成你的答案,有必要做一些事情来工作。
添加 gems:
添加 config/application.rb 的配置
并在索引处显示图像,只需添加以下代码:
Just for complete your answer it's necessary do somethings to work.
Add the gems:
Add the configuration of config/application.rb
And to show the images at index just added this code: