feature: custom controller #215

traxanos opened this Issue Jun 21, 2011 · 41 comments

for custom buisness logics. eg.

  • wizards
  • complex forms
  • statistics
  • reports
  • combined searches
  • and much more


You can add custom actions - I just added that to the documentation yesterday. :)

To add a collection action, use the collection_action method:

  collection_action :import_csv do
    # do csv import
    redirect_to :action => :index, :notice => "CSV imported successfully!"

To add a member action, use the member_action method:

  member_action :lock, :method => :post do
    redirect_to :action => :show, :notice => "Locked!"

Would that solve your issue?



no, i want to build my own controller (resourceless) with custom routes.

e.g: /admin/trackings/:year/:month/:day


Well... If you want to build your own controller, you can just build your own controller. :)

Create it in app/controller/admin/tracking_controller.rb and add your routes to config/routes.rb. Don't forget to authenticate your admin user though. (hint: https://github.com/gregbell/active_admin/blob/master/lib/active_admin/resource_controller.rb#L90)

That should solve your issue then. Or maybe I missed something?


Mmmh. You gonna loose the layout if you do that actually. We'll see how we can address that. Looks like @gregbell was about to work on it. :)


that correct you gonna loose the layout :D i think the best way is, to have a ActiveAdmin::Controller::Base.
then you can use it as base for ActiveAdmin::Controller::Ressource (curreny ActiveAdmin::ResourceController)

function of the base:

  • methods for layout 'active_admin'
  • helper methods for the layout
  • new helper methods for add action items, sidebar, menu and title

+1 on this. We need a mechanism to create generic controllers that hook into the admin interface.



We've got a custom controller and views to edit translations of a globalize'd model in a single edit view. We couldn't figure out a way to do it with active admin's customizations. I think just hooking custom controller/views in the admin interface is the easiest way to incorporate highly customized interfaces. Thanks!






I'm playing with active admin for 30 minutes, but +1 :)




I'm playing with active admin for 30 minutes, but +1 :) [1]


Absolutely needed feature, is it planned?



+1 :D


Anything new on this ? Would be really useful. Great gem btw!


+1 on this also. I really need to create a wizard for an administration section seeing as I can't get activeadmin to play nicely with complicated nested resources.




+1 agree! definitly need this feature.

cj commented Jan 18, 2012



@pcreux, do you know what the default routes are for custom controller actions? Or do I need to add them myself? For example, in the docs there is an example like this:

ActiveAdmin.register Post do
member_action :comments do
@post = Post.find(params[:id])

What would the route for that page look like?


@fu-media: Thanks!


@fu-media, here's the code that worked for me:

action_item :only => :show do
link_to('Update Status', status_admin_order_path(order.id))
member_action :status do
@order = Order.find(params[:id])


You can now create custom pages in Active Admin (>=0.4.0).

Docs available at http://activeadmin.info/docs/9-custom-pages.html

@gregbell gregbell closed this Feb 3, 2012

Custom pages don't actually work the same way a controller would. I.e. I'm trying to bind my custom Redis wrapper to it but that actually means I need to write tons of code for a very primitive problem. I used a custom page for index so correct me if I'm wrong but it seems that I need to create a separate page for new/create/show actions?



Custom pages gives you an index action. If you need a custom index, new, create show actions you'd better create your own controlller rather than using the active admin dsl. :) Where does your Redis wrapper lives? ActiveRecord layer?


But I like ActiveAdmin and hate writing my semi-admin-interfaces =) I've already implemented the functionality I needed by using 5 custom pages (messy=). That would be really awesome to have a custom controller behind ActiveAdmin authentication with it's layout.


You can add custom routes to use the same active admin controller..

namespace :admin do
   resources :redis , :only => [:create, :destroy, :show]

That's a good point, RobWu. Any thoughts about using AA layout in a DRY manner?


Did not find a better solution..

Next problems is also that the instance variables inside the controller are not present in the views..


@gregbell : Your provided link not working. Here is working link http://activeadmin.info/docs/10-custom-pages.html





@seanlinsley seanlinsley locked and limited conversation to collaborators Oct 13, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.