我正在尝试将全局导航菜单项添加到我的Active Admin安装("仪表板"导航按钮旁边).Active Admin表示这可以在他们的网站上进行,但他们没有任何关于如何实现它的文档.有谁知道如何做到这一点?
编辑:对不起,我应该更清楚.我想添加一个指向由任意文本/链接对组成的全局导航的链接.IE,如果我想在活动管理员的全局导航中添加带有文本"Google"的http://google.com链接,我该如何实现?
我有两个模型User和ActiveAdmin,我想在其中应用我的devise集成.
我有custom_failure.rb以下情况
class CustomFailure < Devise::FailureApp
def redirect_url
login_path
end
# def redirect_url
# root_path
# end
def respond
if http_auth?
http_auth
else
redirect
end
end
end
Run Code Online (Sandbox Code Playgroud)
这似乎很有效.
另外,可以在我的application controller喜欢中定义:
def after_sign_in_path_for(resource)
# case resource
if resource.is_a?(Admin)
admin_dashboard_path
else
root_path
end
end
Run Code Online (Sandbox Code Playgroud)
和
def after_sign_out_path_for(resource_or_scope)
login_path
end
Run Code Online (Sandbox Code Playgroud)
但问题是如何使用它resource,custom_failure.rb以便我可以相应地重定向登录user login或为admin login?? 根据当前情况,它总是重定向到用户登录页面?
我想为ActiveAdmin设置基本身份验证,内部设计解决方案不适用于我的情况.为此,我希望能够将中间件添加到ActiveAdmin引擎,然后将其捆绑到我的应用程序中.我设法做的是:
ActiveAdmin::Engine.configure do |config|
config.middleware.use Rack::Auth::Basic do |username, password|
username == 'admin' && password == 'root'
end
end
Run Code Online (Sandbox Code Playgroud)
但显然这不起作用,因为我的主动管理路线仍未受到保护.我怎样才能有效地做到这一点?不,我不想用基本身份验证保护我的整个网站.
我想用自定义页面替换ActiveAdmin中的默认仪表板页面.
这主要是因为我想要一个基于资源的页面,即用ActiveAdmin.register和不用生成的页面ActiveAdmin.register_page.
我刚刚删除了该dashboard.rb文件,希望这MyCustomAdmin是一个常规(和工作)ActiveAdmin资源,只需取代仪表板.
但它没有,而是我得到这个错误:
uninitialized constant Admin::DashboardController
Run Code Online (Sandbox Code Playgroud)
所以我更改了ActiveAdmin初始化程序并设置:
# config/initializers/active_admin.rb
config.root_to = 'my_custom_admin#index'
Run Code Online (Sandbox Code Playgroud)
我也MyCustomAdmin喜欢这样:
# app/admin/my_custom_admin.rb
ActiveAdmin.register MyCustomAdmin do
menu :priority => 1, :label => 'Report'
index do
column "column 1 title", :column1
end
end
Run Code Online (Sandbox Code Playgroud)
我的模特中还有:
# app/models/my_custom_admin.rb
class MyCustomAdmin < ActiveRecord::Base
end
Run Code Online (Sandbox Code Playgroud)
所以问题是当我尝试访问时localhost:3000/admin我得到错误:
uninitialized constant Admin::MyCustomAdminController
Run Code Online (Sandbox Code Playgroud)
但是,如果我去localhost:3000/admin/my_custom_admin它的工作就好了.
为什么localhost:3000/admin不工作?
这可能是非常简单的事情,但我似乎无法弄清楚为什么我的收集行动没有显示出来.根据文档,我需要做的就是调用传递给寄存器的块中的collection_actions方法.我想在我的用户的管理页面中添加一个名为"Notify All"的操作.这是代码:
ActiveAdmin.register User do
menu :label => "Users", :priority => 3
filter :twitter_id
filter :facebook_id
filter :created_at
filter :allows_notifications
filter :created_at
actions :all, except: [:destroy, :new]
collection_action :notify_all, :method => :post do
puts "notifying...."
end
batch_action :flag do |selection|
puts "flagging...."
end
index do
selectable_column
column "", :sortable => false do |user|
"<img src='#{user.avatar_url}' alt='user avatar' style='width:24px; height:24px;'/>".html_safe
end
column :uuid
column :twitter_id
column :facebook_id
column :allow_notifications do |user| user.allow_notifications ? "true" : "false" end
column :blocked do |user| …Run Code Online (Sandbox Code Playgroud) 我在activeadmin页面中的资源无效表单遇到了一些问题:
ActiveAdmin.register_page 'TestDashboard' do
menu :label => 'TestDashboard'
content title: 'TestDashboard' do
columns do
column do
div do
semantic_form_for 'dashboard', :url => '#' do |f|
f.inputs :name => 'Configure', :class => 'inputs' do
f.input :target
f.input :name
end
end
end
end
end
end # content
end
Run Code Online (Sandbox Code Playgroud)
仅显示最后一个字段(名称).生成的html是:
<form novalidate="novalidate" method="post" class="formtastic dashboard" action="#" accept-charset="UTF-8">
<div style="margin:0;padding:0;display:inline"><input type="hidden" value="?" name="utf8">
<input type="hidden" value="3424234blabla" name="authenticity_token">
</div>
<fieldset class="inputs">
<legend>
<span>Configure</span>
</legend>
<ol>
<li id="dashboard_name_input" class="string input required stringish">
<label for="dashboard_name" class="label">Name<abbr title="required">*</abbr></label> …Run Code Online (Sandbox Code Playgroud) 我正在开发一个创建Web博客的Ruby on Rails项目.我希望在Post模型中添加一个名为features的布尔数据库字段.该字段应该可以通过我添加的活动管理界面进行编辑.
我使用了以下代码,但我甚至没有在网站上显示另一个列.
$rails generate migration addFeatured featured:boolean
$rake db:migrate
Run Code Online (Sandbox Code Playgroud)
我是Ruby on Rails的新手,非常感谢任何帮助.
我的index.html.erb文件(views)中的相关代码:
<th>Featured Post</th>
<td><%= post.featured %></td>
Run Code Online (Sandbox Code Playgroud)
Schema.rb:
ActiveRecord::Schema.define(:version => 20141126015126) do
create_table "active_admin_comments", :force => true do |t|
t.string "namespace"
t.text "body"
t.string "resource_id", :null => false
t.string "resource_type", :null => false
t.integer "author_id"
t.string "author_type"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "active_admin_comments", ["author_type", "author_id"], :name => "index_active_admin_comments_on_author_type_and_author_id"
add_index "active_admin_comments", ["namespace"], :name => "index_active_admin_comments_on_namespace"
add_index "active_admin_comments", ["resource_type", "resource_id"], :name => …Run Code Online (Sandbox Code Playgroud) 我有一个Ruby on Rails和ActiveAdmin应用程序.除了添加和注册几个模型之外,我基本上没有更改任何默认配置.
我希望使用类似的路由启用我的应用程序,GET /heartbeat并使用简单的字符串响应客户端/用户.我想知道我怎么能做以下步骤:
routes.rb文件.app/controllers路径下添加自定义控制器.我正在使用 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 页面上,我才需要此验证。它不应该存在于站点的其他任何地方,所以我不想在模型中这样做。
出于某种原因,上面的代码不起作用。虽然表单字段确实显示了*,但它仍然提交。如何仅在此页面上需要此输入?
我使用 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)
我认为有更好的方法来处理这个问题......