我想添加"is_admin?" 过滤到ActiveAdmin初始化程序.我应该在哪个文件中定义"is_admin?" 方法?
# == Controller Filters
#
# You can add before, after and around filters to all of your
# Active Admin resources from here.
#
config.before_filter :is_admin?
Run Code Online (Sandbox Code Playgroud) 解决方案:查看评论
构建一个新的rails 3.1 app.从一个基本的blog_entries模型开始,以获得它的悬念.没有惊喜.
然后我添加了ActiveAdmin,让我的现有模型正常工作.
但是现在当我尝试用这个来构建一个新模型/ etc时:
rails g scaffold Community name:string guid:string
Run Code Online (Sandbox Code Playgroud)
一切似乎都是正确的(视图,迁移),除了控制器没有CRUD选项,看起来像这样:
class CommunitiesController < InheritedResources::Base
end
Run Code Online (Sandbox Code Playgroud)
问题是ActiveAdmin使用inherited_resources来防止手动rails脚手架正常工作.
尽管ActiveAdmin使用inherited_resources,有没有人知道如何"正确"强制rails到scaffold?
我想通过Activeadmin的formtastic制作动态选择选项,如下所示:
form do |f|
f.inputs "Exam Registration Details" do
f.input :user_id, :as => :select, :collection => User.where(:admin => 'false')
#selects user from list. WORKING
f.input :student_id, :as => :select, :collection => Student.joins(lessons: :user)
#collection of students will change to students who have lessons with chosen user. NOT WORKING, returns all students who have lessons.
f.input :lesson_id, :as => :select, :collection => Lesson.joins(:student, :user)
#collection of lessons will change to reflect lessons connected by chosen user and student. NOT …Run Code Online (Sandbox Code Playgroud) 我正在使用friendly_id5.0.0.rc1,还有active_admin.
看起来一切都按预期完美地工作,除了slug在active_admin中更新记录的属性/列没有做任何事情(它保持相同)
我发现只使用控制台的行为相同:
p = Post.first
p.slug
#=> 'test'
p.slug = 'another-test'
p.save
#=> true
p.slug
#=> 'test
Run Code Online (Sandbox Code Playgroud)
我的配置:
FriendlyId.defaults do |config|
config.use :reserved
config.reserved_words = %w(admin new edit index session users register)
config.use :finders
config.use :slugged
config.slug_column = 'slug'
config.sequence_separator = '-'
config.use Module.new {
def should_generate_new_friendly_id?
slug.blank? || slug_changed?
end
}
end
Run Code Online (Sandbox Code Playgroud)
我的模特:
class Post < ActiveRecord::Base
default_scope { order('created_at DESC') }
validates :title, presence: true
validates :body, presence: true
validates :views, …Run Code Online (Sandbox Code Playgroud) 我想在菜单设置父自定义菜单标签active_admin一样
Parent label
custom label 1
custom label 2
custom label 3
Run Code Online (Sandbox Code Playgroud)
问题是当我设置它时
ActiveAdmin.register Example do
menu parent: 'Parent'
menu label: 'Label 1'
end
Run Code Online (Sandbox Code Playgroud)
菜单父级不起作用.我该如何解决?
谢谢!
假设我有一个带有:email字段的User类.我们假设我使用activeadmin来管理用户.
制作一个返回与一个字符串匹配的电子邮件的过滤器,例如"smith",非常简单.在admin/user.rb,我只是包括该行
filter :email
Run Code Online (Sandbox Code Playgroud)
这给了我一个完成工作的过滤器小部件.
但是,此过滤器不允许我搜索多个项的交集.我可以搜索包含"smith"的电子邮件,但不能搜索包含"smith"和".edu"的电子邮件.
Google告诉我,activerecord 在引擎盖下使用Ransack,而Ransack演示具有允许多个术语搜索的"高级"模式.
将多项搜索小部件放入activeadmin的最简单方法是什么?
理想情况下,我想要一个小部件,允许我输入smith .edu或smith AND .edu过滤包含这两个术语的电子邮件.
我目前正在制作这样的协会:
show do
h3 project.title
panel "Utilisateurs" do
table_for project.roles do
column "Prenom" do |role|
role.user.firstname
end
column "Nom" do |role|
role.user.lastname
end
column "email" do |role|
role.user.email
end
column "Role" do |role|
role.role_name.name
end
end
end
end
# override default form
form do |f|
f.inputs "Details" do # Project's fields
f.input :title
f.input :code
end
f.has_many :roles do |app_f|
app_f.inputs do
# if object has id we can destroy it
if app_f.object.id
app_f.input :_destroy, :as => :boolean, :label => …Run Code Online (Sandbox Code Playgroud) 我有一个使用mongoid,database_cleaner和rspec的现有项目.我尝试使用可用的active_admin补丁添加active_admin .ActiveAdmin假定它在ActiveRecord项目中,最具体的是通过它对meta_search gem的依赖.
当我去运行我的规格时,它们都会因以下错误而失败:
Failure/Error: Unable to find matching line from backtrace
ActiveRecord::ConnectionNotEstablished:
ActiveRecord::ConnectionNotEstablished
# ./spec/support/database_cleaner.rb:12:in `block (2 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
相关库的gem版本如下:
测试失败的文件,spec/support/database_cleaner.rb:
require 'database_cleaner'
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.orm = "mongoid"
end
config.before(:each) do
DatabaseCleaner.clean
end
end
Run Code Online (Sandbox Code Playgroud) 用户has_many交易.我有活动管理员当前设置为使用belongs_to:user in admin/transactions.rb在用户下嵌套用于基本CRUD的事务.但是,我还需要一个顶级视图,用于显示跨用户的事务记录子集的事务.我怎样才能完成第二部分?
我正在使用rails 4 + activeadmin在ruby 1.9.3p392上运行.
当我要去的时候
http://127.0.0.1:3000/admin/login
Run Code Online (Sandbox Code Playgroud)
我得到一个错误:
ActiveAdmin :: Devise :: Sessions#new中的ArgumentError
显示C:/Ruby/lib/ruby/gems/1.9.1/bundler/gems/active_admin-85b9f8164809/app/views/active_admin/devise/sessions/new.html.erb其中第5行引发:
错误的参数数量(3个用于2)
提取的来源(第5行):
<h2><%= title "#{render_or_call_method_or_proc_on(self, active_admin_application.site_title)} #{t('active_admin.devise.login.title')}" %></h2>
<% scope = Devise::Mapping.find_scope!(resource_name) %>
<%= active_admin_form_for(resource, :as => resource_name, :url => send(:"#{scope}_session_path"), :html => { :id => "session_new" }) do |f|
f.inputs do
resource.class.authentication_keys.each { |key| f.input key, :input_html => {:autofocus => true}}
f.input :password
Run Code Online (Sandbox Code Playgroud) activeadmin ×10
activerecord ×1
formtastic ×1
friendly-id ×1
mongoid ×1
ransack ×1
rspec ×1
ruby ×1
scaffolding ×1