0

I wan't to add image upload field inside active admin interface.This is the view where I want to be able get photo upload

I tried some earlier suggestions From here

ActiveAdmin.register Product do
  form :html => { :multipart=>true } do |f|
  f.inputs :new_product  do
  f.input :name
  f.input :price
  f.input :category
  f.input :description

  f.has_many :prod_images  do |p|
    p.input :photo, :as => :file, :label => "Image",:hint =>   p.template.image_tag(p.object.photo.url(:thumb)) 
    p.input :_destroy, :as=>:boolean, :required => false, :label => 'Remove image'
  end
end

f.buttons  

end

Using this example I got such error

undefined method `klass' for nil:NilClass

It says that error is from here app/views/active_admin/resource/new.html.arb where line #1 raised but how can I access that file, because in explorer it is not showing up? Thanks

4

2 回答 2

0

尝试构建一个 prod 图像,像这样。

f.has_many :prod_images, f.object.prod_images.build do |p|
于 2013-07-11T07:37:42.157 回答
0

我设法使用此代码获取文件上传字段

ActiveAdmin.register Product do
 form :html => { :enctype => "multipart/form-data" } do |f|
f.input :photo, :as => :file, :hint => f.template.image_tag(f.object.photo.url(:thumb))
end

但现在我无法添加提交按钮 :D 所以我仍在努力:)

编辑

ActiveAdmin.register Product do
  form :html => { :enctype => "multipart/form-data" } do |f|
    f.input :photo, :as => :file
    f.buttons
  end
end

这仅显示创建和取消之类的按钮,但未显示文件字段,我检查了表单示例,但没有成功。

编辑2

class Product < ActiveRecord::Base
  attr_accessible :category_id, :description, :manufacturer_id, :name, :photo 
  extend FriendlyId
   has_attached_file :photo,
     :styles => {
     :thumb=> "100x100#",
     :large => "290x170",
     :medium=> "120x120"}

  friendly_id :name, use: [:slugged, :history]
  belongs_to :manufacturer
  belongs_to :category
end
于 2013-07-11T07:55:52.627 回答