activeadmin

How to give ActiveAdmin its own application layout? — Rails newbie

若如初见. 提交于 2019-12-24 01:01:59
问题 It's probably a dead simple question. Right now it uses the default application layout file. How can I create one just for AdminAdmin in order keep it separate from the one used on the main site? 回答1: Read layouts and rendering guide, there is paragraph about :layout option. You can specify layout, or set it to false, to render without layout at all. render :layout => 'special_layout' render :layout => false 回答2: If my memory does not fail me again !! ;-) this rails cast talk about this. But

Rails3 Active Admin: How to display only Open status records when first click on Shipments tag?

此生再无相见时 提交于 2019-12-24 00:21:02
问题 I'm using ActiveAdmin. I have a list of Shipments with status (as a string) of Open and Closed. When the user clicks on the Shipments tab, I want to display only the Open shipments. How can I do that? Of course, the user could later choose to see the Closed shipments by using the filter. But I want the default to initially only show the Open shipments. 回答1: Probably best way will be to create scopes in model. AA automatically gets your scopes and creates tabs above table in index view.

Using ActiveAdmin's DSL with shared module includes

谁说我不能喝 提交于 2019-12-23 22:37:29
问题 I'm trying to make some common/shared actions for my models registered with ActiveAdmin. I have the following code: # app/admin/concerns/activatable.rb module Activatable def self.included(dsl) dsl.member_action :deactivate, method: :put do dsl.resource.deactivate! redirect_to dsl.resource_path, notice: 'Deactivated.' end end end # app/admin/course.rb ActiveAdmin.register Course do include Activatable # ... end When I run rails server , the server immediately quits having thrown the following

ActiveAdmin: Filter by count of child objects

天大地大妈咪最大 提交于 2019-12-23 22:32:28
问题 In a Ruby on Rails app that heavily relies on ActiveAdmin, I have a Sponsor model, which is associated with a Sponsorship model. One sponsor can sponsor many children, so one sponsor can have many sponsorships . What I would like to do, is to be able, on the Sponsor index page, to filter out sponsors by the number of sponsorships they have. So that, for example, I want to see only those sponsors who have more than one sponsorship, or less than five, and so on. You get the idea. In Ruby-speak,

How to create an object of a STI subclass using ActiveAdmin

情到浓时终转凉″ 提交于 2019-12-23 21:24:02
问题 Given the following setup(which is not working currently) class Employee < ActiveRecord::Base end class Manager < Employee end ActiveAdmin.register Employee do form do |f| f.input :name f.input :joining_date f.input :salary f.input :type, as: select, collection: Employee.descendants.map(&:name) end end I would like to have a single "new" form for all employees and be able to select the STI type of the employee in the form. I am able to see the select box for "type" as intended but when I hit

Active admin redirects after login

浪尽此生 提交于 2019-12-23 18:11:21
问题 When an admin logs in, it automatically redirects to the main home page (i.e. not the admin dashboard). I'm not sure why it does this or how to change it... routes.rb ActiveAdmin.routes(self) devise_for :admin_user, ActiveAdmin::Devise.config get "guidelines/topic" get "guidelines/topichospital" get "guidelines/topicspecialty" get "guidelines/favourite" get "profiles/show" get "guidelines/show" root :to => 'guidelines#index' my application_controller.rb has been changed to redirect after user

active admin sort a count of a has_many column

泪湿孤枕 提交于 2019-12-23 13:15:47
问题 Using the Active Admin framework, I can add a 'users' column that totals the count for a particular 'club' by doing this: ActiveAdmin.register Club do index do column 'Users' do |club| club.users.count end end end Can I make this sortable somehow? 回答1: You could add a counter cache column on teh User model's belongs_to :club , and then make your index like so: ActiveAdmin.register Club do index do column 'Users', sortable: :users_count do |club| club.users.count end end end 来源: https:/

how to add sorted elements in the filter dropdown in activeadmin rails

家住魔仙堡 提交于 2019-12-23 09:17:39
问题 I have a Post model, PostSource model. A PostSource has many posts, a post belong to one PostSource. Using ActiveAdmin, in the Index action of the Post, I am displaying a filter of PostSource this way: filter :post_source, label: 'Source' filter :category, as: :select, collection: Category.order(:name).collect { |cat| [cat.name, cat.id] } with the controller as: controller do def scoped_collection end_of_association_chain.includes(:post_source) end end It displays the source, but does not

Disable CSV downloads in Active Admin

时光怂恿深爱的人放手 提交于 2019-12-23 08:51:07
问题 I am using the Active Admin gem and I would like to hide or remove the links on the index page of each model allowing users to download data as CSV, XML or JSON. Is there any way to do this? 回答1: There is now an option :download_links on the index method, so you omit the download links if you want. For example: ActiveAdmin.register Post do index :download_links => false do # whatever end end 回答2: You should use it as a option of index, but do not separate it from the column functions. Use it

Active Admin: How to set page title?

无人久伴 提交于 2019-12-23 06:51:07
问题 This seems like it should be relatively simple, but I've had some trouble tracking down the answer: How do you set the page title in ActiveAdmin? 回答1: Consolidating answers and adding a little: Most of this is on this page on the wiki (or I'll put it there soon). Within the file that registers your model for activeadmin (e.g. app/admin/user.rb), you can have ActiveAdmin.register User do # a simple string index :title => "Here's a list of users" do ... end # using a method called on the