使用 Paperclip 时 ActiveAdmin 不上传图像

发布于 2024-12-22 03:32:51 字数 1119 浏览 0 评论 0原文

我已遵循所有指南和答案,所有内容都显示正确,但实际上传并未发生:(

这是我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鱼忆七猫命九 2024-12-29 03:32:51

问题是该死的 attr_accessible 没有 :image

The problem was the damn attr_accessible not having :image

同展鸳鸯锦 2024-12-29 03:32:51

为了完成你的答案,有必要做一些事情来工作。

添加 gems:

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

Just for complete your answer it's necessary do somethings to work.

Add the gems:

gem 'paperclip'
gem 'fog'

Add the configuration of config/application.rb

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

And to show the images at index just added this code:

index do
  column "Image" do |epc|
    link_to(image_tag(epc.imagem.url(:thumb), :height => '100'), admin_epc_path(epc))
  end
  default_actions
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文