Active Admin图片上传

时间:2015-11-02 11:16:56

标签: ruby-on-rails ruby activeadmin

我是铁轨上的新红宝石和红宝石。我希望使用有效的管理员上传图片我遵循此代码
应用程序\ ADMIN \ book.rb ActiveAdmin.register Book do

# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
 permit_params :list, :of, :attributes, :on, :model
#
# or
#
# permit_params do
#   permitted = [:permitted, :attributes]
#   permitted << :other if resource.something?
#   permitted
# end
index do
  column :name
  column :image


  column :author
  column :genre
  column :price
  actions
end
form :html => { :enctype => "multipart/form-data" } do |f|
   f.inputs "Details" do
    f.input :image, :as => :file, :hint => f.template.image_tag(f.object.image.url(:medium))
    f.input :author
    f.input :name
  end
  f.actions
 end
end


应用\模型\ book.rb

class Book < ActiveRecord::Base
  belongs_to :author
  belongs_to :genre
has_attached_file :image, :styles => { :medium => "238x238>", 
                                   :thumb => "100x100>"
                                 }
end

是的,我在创建页面中看到了文件上传按钮。但是不要保存表格。

1 个答案:

答案 0 :(得分:0)

您应该将参数添加到允许的参数列表中。

#
# I can assume these are your fields that is 
# what you will submit with your form. 
# Try replacing my code with yours. 
# That will work if you don't make other changes.
#
permit_params :image, :author, :name

让我知道它是怎么回事。如果您遇到任何错误,请分享您的日志,如果需要,我会更新我的答案。