我正在使用Rails 3.2和ActiveAdmin 0.4.4开发一个应用程序.我的模型名为Teaser(/app/models/teaser.rb):
class Teaser < ActiveRecord::Base
attr_accessible :img, :name, :url
validates :img, :name, :presence => true
mount_uploader :img, TeaserUploader
end
Run Code Online (Sandbox Code Playgroud)
我添加了ActiveAdmin(/app/admin/teaser.rb):
# encoding: UTF-8
ActiveAdmin.register Teaser do
form do |f|
f.inputs "Teaser" do
f.input :name, :label => '?????'
f.input :url, :label => '??????'
f.input :img, :as => :file, :label => '????????'
end
f.buttons
end
end
Run Code Online (Sandbox Code Playgroud)
现在,当我去'http:// localhost:3000/admin/teasers'时,我收到以下错误:
显示C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/app/views/active_admin/resource/index.html.arb第1行引发:收集不是分页范围.在调用之前设置collection.page(params [:page]).per(10):paginated_collection.
当我在linux上测试我的应用程序时,我得到了同样的错误(Ubuntu 12.04).
我可以通过这种方式解决这个问题(/app/admin/teaser.rb):
# encoding: UTF-8
ActiveAdmin.register Teaser, :as => 'Somename' do
Run Code Online (Sandbox Code Playgroud)
但是如果我使用这种方法,我就无法使用/app/config/locales/XX.yml来翻译这个模型
所有其他模型都正常工作.
我正在尝试将全局导航菜单项添加到我的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) 我是Rails和ActiveAdmin的新手.
我希望有一个类似Django管理员的界面,我的应用程序模型,所以我可以管理产品和其他东西.
到目前为止,我有admin_users我可以在我的应用程序中添加或删除管理员用户的URL,这太棒了.
我正在使用Rails 3,我想知道我是否可以添加除用户之外的新菜单,以便我可以管理其他模型 dashboard
我试过了 rails generate active_admin:resource Product
它创建一个名为product.rbon 的文件,app/admin/但它不起作用,这是我的Product模型product.rb
class Product < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
belongs_to :category
has_many :line_items
has_many :orders, through: :line_items
validates_presence_of :category_id, :name, :price_cents
attr_accessible :avatar
has_attached_file :avatar, :styles => { :medium …Run Code Online (Sandbox Code Playgroud) 我有一个Ruby on Rails和ActiveAdmin应用程序.除了添加和注册几个模型之外,我基本上没有更改任何默认配置.
我希望使用类似的路由启用我的应用程序,GET /heartbeat并使用简单的字符串响应客户端/用户.我想知道我怎么能做以下步骤:
routes.rb文件.app/controllers路径下添加自定义控制器.