feature: custom controller #215

Closed
traxanos opened this Issue Jun 21, 2011 · 41 comments
@traxanos

for custom buisness logics. eg.

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

Hello,

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!"
  end

To add a member action, use the member_action method:

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

Would that solve your issue?

Cheers

@traxanos

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

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

@pcreux

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?

@pcreux

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. :)

@traxanos

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
@devjj

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

@juni0r

+1

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!

@Overbryd

+1

@pcreux
@rweng

+1

@MatthieuBarthel

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

@RobWu

+1

@robertokl

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

@Bazai

Absolutely needed feature, is it planned?
+1

@ghost

whatever

+1 :D

@vidriloco

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

@kirkbushell

+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.

@Ecco

+1

@antonzaytsev

+1 agree! definitly need this feature.

@cj
cj commented Jan 18, 2012

+1

@JuliaLovel

@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])
end
...

What would the route for that page look like?

@ghost
@JuliaLovel

@fu-media: Thanks!

@JuliaLovel

@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))
end
member_action :status do
@order = Order.find(params[:id])
end

@ghost
@gregbell

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
@fenelon

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?

@pcreux

@fenelon

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?

@fenelon

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.

@RobWu

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

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

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

@RobWu

Did not find a better solution..

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

@Ruby-rocker

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

@adisos

+1

@marat93

+1

@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.