【问题标题】:Active Admin image upload主动管理员图片上传
【发布时间】:2015-11-02 11:16:55
【问题描述】:

我是新的 ruby​​ 和 ruby​​ on rails。我想用活跃的管理员上传图片
我遵循这段代码
应用\管理员\book.rb ActiveAdmin.register 书做

# 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


app\models\book.rb

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

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

【问题讨论】:

  • 我无法理解您的问题。你能重新表述你的问题吗?
  • 我做到了,图书杂物、作者杂物和流派杂物以及活跃的管理员。我想为我的书添加书籍图片。我可以用 Rails 做到这一点,但我想使用活动管理员。对不起我的英语不好。你明白我了吗?谢谢。
  • 这就是您的意思,您不能将您的记录保存在活动管理员中吗?但是您可以在活动管理员之外执行此操作?
  • 是的,我的记录是不保存

标签: ruby-on-rails ruby activeadmin


【解决方案1】:

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

#
# 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

让我知道进展如何。如果您遇到任何错误,请分享您的日志,如果需要,我会更新我的答案。

【讨论】:

  • " 图书模型缺少 'image_file_name' 所需的 attr_accessor"
  • 使用回形针还是载波?
猜你喜欢
  • 2013-09-07
  • 2015-06-29
  • 1970-01-01
  • 1970-01-01
  • 2014-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多