使用Paperclip时,ActiveAdmin不会上传图像

时间:2011-12-19 09:23:49

标签: ruby-on-rails ruby 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"

我也试过没有路径,也没用。

这是我的迁移:

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

2 个答案:

答案 0 :(得分:2)

问题是该死的attr_accessible没有:image

答案 1 :(得分:0)

只是为了完成你的答案,有必要做一些工作。

添加宝石:

gem 'paperclip'
gem 'fog'

添加config / application.rb

的配置
config.paperclip_defaults = {:storage => :fog, 
                             :fog_credentials => {:provider => "Local", 
                                                  :local_root => "#{Rails.root}/public"}, 
                             :fog_directory => "", 
                             :fog_host => "http://localhost:3000"}

要在索引处显示图像,只需添加以下代码:

index do
  column "Image" do |epc|
    link_to(image_tag(epc.imagem.url(:thumb), :height => '100'), admin_epc_path(epc))
  end
  default_actions
end