我正在使用Ruby on Rails实现通用媒体库.我选择ActiveAdmin来处理我的任务的管理部分,到目前为止它运行良好,除了一件事:它没有按预期显示"选择文件"对话框.
这是ActiveAdmin的"媒体"部分的表单.我有一个名为"Medium"的模型,其中包含以下字段(除了id和timestamp:
asset_file_nameasset_file_sizeasset_content_typeasset_updated_at我的Medium模型看起来像这样:
class Medium < ActiveRecord::Base
has_and_belongs_to_many :galleries
has_and_belongs_to_many :entities
has_attached_file :asset, :styles => { :medium => "300x300>", :thumb => "100x100>" }
attr_accessible :asset
end
Run Code Online (Sandbox Code Playgroud)
我将它添加到ActiveAdmin表单中,如下所示:
form :html => { :enctype => "multipart/form-data" } do |f|
f.input :asset, :as => :file
f.buttons
end
Run Code Online (Sandbox Code Playgroud)
这是我的ActiveAdmin页面的屏幕截图:

我认为我是如何实现这一点没有错.我已经读过,Formtastic历来存在回形针的问题,我不反对切换到attachment_fu或任何其他合适的解决方案.
我还应该注意:我知道我可以添加自定义部分.这不是我理想的解决方案,因为我想保留Formtastic DSL中的所有内容.
谢谢!
我在rails 3应用程序中使用ActiveAdmin和acts_as_taggable,我可以将标记列表显示为编辑页面上的清单,我可以使用控制台添加标签,然后使用表单删除它们,但是它出错了如果我尝试添加标签,则保存表单
"验证失败:上下文不能为空"
我只有一个标记上下文(标签).
ActiveAdmin表单代码是:
form :html => { :multipart => true } do |f|
f.inputs "Details" do
f.input :title
f.input :itinerary, :as => :select, :collection => Itinerary.all
f.input :description
f.input :address
f.input :contact_details
f.input :url
f.input :phone
f.input :nearest_tube
f.input :timetable
f.input :price
f.input :tags, :as => :check_boxes, :multiple => true, :collection => @tags
f.input :image, :as => :file
end
f.buttons
end
Run Code Online (Sandbox Code Playgroud)
在我的模型中
class Ticket < ActiveRecord::Base
has_and_belongs_to_many :itinerary
acts_as_taggable_on :tags
has_attached_file :image, :styles => { :medium …Run Code Online (Sandbox Code Playgroud) 我有一个模型page.rb和模型comment.rb和评论belongs_to页面.我也在使用gem active admin.在索引页面上,我有一个由"过滤器"制作的搜索表单,我有
filter :country
filter :city
filter :category
filter :description_type
filter :title
filter :sight_of_the_day, :as => :select
filter :active, :as => :select
filter :show_in_top, :as => :select
filter :created_at
filter :updated_at
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我想再增加一个过滤器.我想创建一个名为"comments"的复选框,如果选中它,我想查找只有评论的页面.我如何在主动管理员中执行此操作?提前致谢!
对于我的所有ActiveAdmin页面,复选框都不显示,批处理操作下拉列表显示为灰色.我的admin/dashboard.rb:
ActiveAdmin.register_page "Dashboard" do
menu :priority => 1, :label => proc{ I18n.t("active_admin.dashboard") }
content :title => proc{ I18n.t("active_admin.dashboard") } do
div :class => "blank_slate_container", :id => "dashboard_default_message" do
span :class => "blank_slate" do
span I18n.t("active_admin.dashboard_welcome.welcome")
small I18n.t("active_admin.dashboard_welcome.call_to_action")
end
end
end # content
end
Run Code Online (Sandbox Code Playgroud)
一个例子Admin.register,Votes:
ActiveAdmin.register Vote do
permit_params :ip_address, :weight, :response_id
index do
column :response
column :weight
column :ip_address
end
form do |f|
f.inputs do
f.input :response
f.input :ip_address, :as => :string
f.input :weight …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下代码在新页面中使用active-admin创建表单:
ActiveAdmin.register_page "Attach Logger" do
content do
semantic_form_for :project do |f|
f.inputs do
f.input :owner, as: :select, collection: Logger.where(:tested => false)
end
f.actions
end
end
end
Run Code Online (Sandbox Code Playgroud)
但我只看到HTML中没有select标签的按钮:
<div id="active_admin_content" class="without_sidebar">
<div id="main_content_wrapper">
<div id="main_content">
<form accept-charset="UTF-8" action="/activeadmin/attach_logger" class="formtastic project" method="post" novalidate="novalidate">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓" />
<input name="authenticity_token" type="hidden" value="YjpVXb+RYu6xX7IggTQys77bsS98ChuJU02vDZeZR+s=" />
</div>
<fieldset class="actions">
<ol>
<li class="action input_action " id="project_submit_action">
<input name="commit" type="submit" value="Submit Project" />
</li>
</ol>
</fieldset>
</form>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
当我注释掉时,f.actions我可以在HTML中看到select标签:
<div id="active_admin_content" …Run Code Online (Sandbox Code Playgroud) Paperclip::AdapterRegistry::NoHandlerError at /admin/posts/1 No handler found for foo.png
Run Code Online (Sandbox Code Playgroud)
我有一个带有Active Admin的rails 4应用程序,我试图将图像上传到我的Post模型,但我收到了上述错误.这是我的设置
ruby '2.1.2'
gem 'rails', '4.1.6'
gem 'activeadmin', github: 'gregbell/active_admin'
gem 'paperclip'
gem 'aws-sdk'
Run Code Online (Sandbox Code Playgroud)
class Post < ActiveRecord::Base
has_attached_file :image, styles: {
thumb: '100x100>',
square: '200x200#',
medium: '300x300>'
}
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
end
Run Code Online (Sandbox Code Playgroud)
permit_params :image
form do |f|
f.inputs do
f.input :image, as: :file, hint: (f.template.image_tag(f.object.image.url(:thumb)) if f.object.image?)
end
f.actions
end
Run Code Online (Sandbox Code Playgroud)
Paperclip::Attachment.default_options[:storage] = :s3
Paperclip::Attachment.default_options[:s3_host_name] = 's3-eu-west-1.amazonaws.com'
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename' …Run Code Online (Sandbox Code Playgroud) 当我使用formtastic DSL for ActiveAdmin编辑表单时,我得到以下输出:
#<#<Class:0x00000006bd1f68>:0x00000006bd1018> <li class ="file input optional"id ="post_image_input"> <label class ="label"for ="post_image"> Image </ label> <input id ="post_image "name ="post [image]"type ="file"/>
为什么这会从obj.inspect的结果以及如何删除这部分开始呢?
导致此错误的代码在这里:
form :html => { :multipart => true } do |f|
f.inputs do
#...
f.input :image, required: false, hint: f.template.image_tag(f.object.image.url(:medium)).html_safe
#...
end
f.actions
end
Run Code Online (Sandbox Code Playgroud) Rails中的Active Admin默认将分页放在索引页的底部.如何自定义索引页面以将其添加到页面顶部?(有助于立即查看您正在处理的记录/页数,而不是首先需要向下滚动...)
undefined method尝试获取ActiveAdmin表单以使用基于对象的枚举属性的键的选择框时,我仍然收到错误消息。在堆栈溢出后按照建议的方法为枚举配置活动管理表单似乎使我半途而废,尽管我对象的引擎方面似乎通过NoMethodError异常使枚举属性生效。
#/lib/book_store/admin/books
if defined?(ActiveAdmin)
ActiveAdmin.register BookStore::Book, as: 'Book' do
# customize your resource here
form do |f|
f.semantic_errors # shows errors on :base
f.inputs do
f.input :cover_type, as: :select, collection: BookStore::Book.cover_type.keys
end
f.actions # adds the 'Submit' and 'Cancel' buttons
end
permit_params :name, :lead, :excerpt, :description, :price, :slug, :cover_type, :num_pages, :size, :cover_image, :author, :author_id, :category
end
end
#app/models/book_store/book.rb
module BookStore
class Book < ActiveRecord::Base
belongs_to :author
belongs_to :category
enum cover_type: [:soft, :hard]
end
end …Run Code Online (Sandbox Code Playgroud) 我想从复选框的形式保存值作为布尔值,但我有一个数组
我的日志大块"important"=>[""]
或者如果我检查它
"important"=>["", "true"]
我的桌子
t.boolean :important, :default => false
Run Code Online (Sandbox Code Playgroud)
我的表格
f.input :important, :as => :check_boxes,collection:[true]
Run Code Online (Sandbox Code Playgroud)
怎么解决?
我认为我的形式输入问题