Ruby on rails Activeadmin和曲别针:ArgumentError
我使用Activeadmin、回形针和Rails 4。 当我想创建一篇包含多个图像的新文章时,出现以下错误:Ruby on rails Activeadmin和曲别针:ArgumentError,ruby-on-rails,ruby,ruby-on-rails-4,paperclip,activeadmin,Ruby On Rails,Ruby,Ruby On Rails 4,Paperclip,Activeadmin,我使用Activeadmin、回形针和Rails 4。 当我想创建一篇包含多个图像的新文章时,出现以下错误: ArgumentError in Admin::Articles#new wrong number of arguments (1 for 0) 当我尝试只使用一个图像时,我会出现相同的错误 ActiveAdmin:article.rb ActiveAdmin.register Article do controller do def permitted_params
ArgumentError in Admin::Articles#new
wrong number of arguments (1 for 0)
当我尝试只使用一个图像时,我会出现相同的错误
ActiveAdmin:article.rb
ActiveAdmin.register Article do
controller do
def permitted_params
params.permit article: [:title, :images_attributes => [:picture, :id, :_destroy]]
end
end
form do |f|
f.inputs "Project Details" do
f.input :title
f.has_many :images do |p|
p.inputs do
p.input :_destroy, :as => :boolean, :label => "Destroy?" unless p.object.new_record?
p.input :picture, :as => :file, :hint => p.object.new_record? ? "" : f.template.image_tag(p.object.picture.url(:thumb))
end
end
end
f.actions
end
end
class Article < ActiveRecord::Base
has_many :images, :dependent => :destroy
accepts_nested_attributes_for :images, :allow_destroy => true
end
型号:article.rb
ActiveAdmin.register Article do
controller do
def permitted_params
params.permit article: [:title, :images_attributes => [:picture, :id, :_destroy]]
end
end
form do |f|
f.inputs "Project Details" do
f.input :title
f.has_many :images do |p|
p.inputs do
p.input :_destroy, :as => :boolean, :label => "Destroy?" unless p.object.new_record?
p.input :picture, :as => :file, :hint => p.object.new_record? ? "" : f.template.image_tag(p.object.picture.url(:thumb))
end
end
end
f.actions
end
end
class Article < ActiveRecord::Base
has_many :images, :dependent => :destroy
accepts_nested_attributes_for :images, :allow_destroy => true
end
我的操作系统是Ubuntu,我使用ImageMagick-6.8.8-7
当我运行转换的时
我有:/usr/local/bin/convert
development.rb
PaperclipActiveadmin::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# configure paperclip
Paperclip.options[:command_path] = "/usr/local/bin/"
end
解决方案:
将require:false
添加到我的输入:
p.input :picture, :as => :file, :hint => p.object.new_record? ? "" : f.template.image_tag(p.object.picture.url(:thumb)), required: false
在my image.rb中添加一个验证附件内容类型
:
validates_attachment_content_type :picture, :content_type => ["image/jpg", "image/jpeg", "image/png"]
感谢Philip Hallstrom的帮助和您的解决方案,临时解决方案是在您的输入中添加require:false
。像这样:
f.input :image, required: false
刚试过,对我很有效。首先,请使用统一的缩进空格。您同时使用4和2个空格,有时在同一个文件中。Ruby社区建议使用2个空格。你确定你已经安装了所有的gems(回形针需要ImageMagick,一个外部程序)。还有,你使用的是什么操作系统?我认为应该有更多的痕迹。我用两个空格编辑了我的帖子。我的操作系统是Ubuntu,我的ImageMagick版本是v6.8.8-7。没有解决方案,但我现在也遇到了这个错误。另外,它现在在2.3.0.rc3中得到了修复,我只需要更新到最新版本。
validates_attachment_content_type :picture, :content_type => ["image/jpg", "image/jpeg", "image/png"]
f.input :image, required: false