2015-11-02 61 views
1

我是新的红宝石和红宝石在轨道上。我要上传图片与积极管理
我遵循这个代码
应用程序\ ADMIN \ book.rb ActiveAdmin.register书做Active Admin image upload

# 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 

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

+0

我无法理解你的问题。你能重新说出你的问题吗? – Rubyrider

+0

我做过,书籍crud,作者crud和流派污秽与活跃管理员。我想为我的书添加图书图像。我可以用rails做到这一点,但我想使用活动管理员。对不起我的英语不好。你明白我了吗?谢谢。 – balkondemiri

+0

是你的意思,你不能保存你的记录在活动管理权限?但你可以在活动管理员之外做到这一点? – Rubyrider

回答

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 

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

+0

“使用paperclip或carrierwave需要的图书模型缺少attr_accessor for'image_file_name'” – balkondemiri

+0

? – Rubyrider

+0

是的,我用回形针 – balkondemiri