在Active Admin中,是否可以为索引页面中的每个项目添加一个复选框(这并不难),并添加某种菜单以对所有选定项目执行批量操作,例如一次删除所有选定项目.
我找不到另一种方法来创建自定义页面,但我宁愿不这样做; 对我来说似乎有点矫枉过正.
我试着这样做.不幸的是我有覆盖更新的问题,我不知道如何正确地做到这一点.我在另一个地方这样做的方式是:
if params[:user][:password].blank?
params[:user].delete("password")
params[:user].delete("password_confirmation")
end
# ...
user.save!
Run Code Online (Sandbox Code Playgroud)
所以我试图覆盖 update
def update
if params[:user][:password].blank?
params[:user].delete("password")
params[:user].delete("password_confirmation")
end
super
end
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我仍然can't be blank接近密码输入.如何实现预期的行为?
我正在尝试设置一个选择菜单以将 ImageGallery 与产品相关联。ImageGallery 是多态的,因为它在几个模型之间共享。Formtastic 似乎对要做什么感到非常困惑。它试图调用一个名为 Galleryable 的方法,这是我的多态关联的名称,产品模型上的 _id (galleryable_id)。
产品
class Product < ActiveRecord::Base
has_one :image_gallery, as: :galleryable, dependent: :destroy
accepts_nested_attributes_for :image_gallery, :allow_destroy => true
end
Run Code Online (Sandbox Code Playgroud)
画廊
class ImageGallery < ActiveRecord::Base
belongs_to :galleryable, polymorphic: true
validates :title, presence: true
has_many :images, as: :imageable, dependent: :destroy
accepts_nested_attributes_for :images, :allow_destroy => true, reject_if: lambda { |t| t['file'].nil? }
end
Run Code Online (Sandbox Code Playgroud)
主动管理表单
form do |f|
f.inputs "Details" do
f.input :name
f.input :category
f.input :price
f.input :purchase_path
f.input :video_panels
f.input :image_panels
f.input :image_gallery, :as => …Run Code Online (Sandbox Code Playgroud) ruby-on-rails polymorphic-associations formtastic activeadmin
我知道如果索引页是不同类型的(表格、网格、块、博客),ActiveAdmin 支持多个索引页,但我需要有两个索引表页。我试过
index :as => :table do
...
end
index :as => :table do
...
end
Run Code Online (Sandbox Code Playgroud)
但索引页只显示第一个表。有没有办法显示两个表并重命名选项卡?
谢谢
我正在使用 Ruby 2.1 和 Rails 4.1。我安装了 ActiveAdmin (1.0.0.pre2)。我想expires_at在 ActiveAdmin 表单中格式化日期时间字段。我在/app/admin/job.rb使用 jQuery datepicker 选项时尝试过这个:
f.input :expires_at, as: :datepicker, datepicker_options: { date_format: "yy-mm-dd", min_date: Time.to_s + "+7D" }
Run Code Online (Sandbox Code Playgroud)
它以新模式的形式完美运行/admin/jobs/new,但在编辑模式下不起作用/admin/jobs/xx/edit。它总是显示来自 db 的值,例如2015-11-06 15:10:00 UTC.
我也尝试过:value,但它也不起作用。
f.input :expires_at, :value => :expires_at.try(:strftime, '%Y-%m-%d'), as: :datepicker, datepicker_options: { min_date: Time.to_s + "+7D" }
Run Code Online (Sandbox Code Playgroud)
我在/config/locales/en.yml. 但是,我相信它不会影响此类表单日期时间字段。
en:
date:
formats:
long: "%Y-%m-%d"
time:
formats:
long: "%Y-%m-%d %H:%M"
Run Code Online (Sandbox Code Playgroud) 当我使用 Active Admin 表单时,空字符串值保存为 ""(空)而不是 NULL 值。
我应该在初始化程序中设置一个参数来将每个空值保存为 MySQL 中的 NULL 吗?
form do |f|
input :label
input :description, as: :text
input :country
input :city
end
actions
end
Run Code Online (Sandbox Code Playgroud)
这是我的迁移架构:
create_table "projects" do |t|
t.string "label", limit: "40"
t.string "country", limit: "2"
t.string "city", limit: "200"
t.string "description", limit: 600
end
Run Code Online (Sandbox Code Playgroud)
这是我的 Gemfile。
gem 'rails', '~> 5.1.0.rc1'
gem 'mysql2', '>= 0.3.18', '< 0.5'
gem 'puma', '~> 3.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'turbolinks', '~> 5'
gem 'jbuilder', …Run Code Online (Sandbox Code Playgroud) 我正在使用 active_admin。我正在尝试在 activeadmin 中创建一个表单字段:
input :team, as: :select, required: true, collection: Team.all.pluck(:name, :id), include_blank: "Please enter a team", allow_blank: false
Run Code Online (Sandbox Code Playgroud)
只有在这个特定的 activeadmin 页面上,我才需要此验证。它不应该存在于站点的其他任何地方,所以我不想在模型中这样做。
出于某种原因,上面的代码不起作用。虽然表单字段确实显示了*,但它仍然提交。如何仅在此页面上需要此输入?
我正在使用 Active admin 来编辑我的应用程序中的所有模型,并且以前使用过回形针。在这个应用程序中,我使用 Active Storage on 和具有以下功能的活动模型:
has_many_attached :images
Run Code Online (Sandbox Code Playgroud)
我发现这种方式可以上传多张图片
form do |f|
columns do
column do
f.inputs do
[removed stuff here]
f.input :images, as: :file, input_html: { multiple: true }
end
f.submit
end
end
end
Run Code Online (Sandbox Code Playgroud)
但我真的希望能够查看、更改或删除表单中的单个图像,每个图像具有单独的输入字段,并在列表末尾添加另一个图像的字段。我怎么做?它甚至可行吗?
我使用 ActiveAdmin 作为我的应用程序的后台,我有以下三个模型:
class Organization
has_many :organization_collection_relations
has_many :collections, through: :organization_collection_relations
end
class OrganizationCollectionRelation
belongs_to :organization
belongs_to :collection
after_destroy :do_something
end
class Collection
has_many :organization_collection_relations
has_many :organizations, through: :organization_collection_relations
end
Run Code Online (Sandbox Code Playgroud)
在我的编辑页面中,Organization我有 和f.input :collections。当我编辑和组织时,例如删除所有集合,问题就出现了。回调after_destroy方法do_something没有被触发。因此,我必须在活动管理文件的控制器部分中采取解决方法。
controller do
def update
resource = Organization.find(params[:id])
former_ids = resource.collection_ids
super
new_ids = resource.reload.collection_ids
# my logic here
end
end
Run Code Online (Sandbox Code Playgroud)
我认为有更好的方法来处理这个问题......
我正在使用 Ruby-2.5.5 、 Rails 5.2.2.1 和 Activeadmin 1.4.3 开发一个项目
在 Activeadminresort显示页面上,我尝试添加一个表单来更新resort. 到目前为止我在里面添加了以下内容show do
show do
...
div do
semantic_form_for [:admin, resort], builder: ActiveAdmin::FormBuilder do |f|
f.inputs do
f.input :name
f.input :description
end
f.actions
end
end
end
Run Code Online (Sandbox Code Playgroud)
但是,我得到的只是Update Resort显示的按钮:
有什么想法如何显示输入字段吗?
activeadmin ×10
ruby-on-rails ×10
formtastic ×3
ruby ×2
activerecord ×1
bulk ×1
callback ×1
devise ×1
indexing ×1
passwords ×1