Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

feature: custom controller #215

Closed
traxanos opened this Issue · 36 comments

23 participants

Marco S Philippe Creux Joseph Jaramillo Scott Andreas Korth Lukas Rieder Robin Wenglewski Matthieu Barthel Robin Wunderlin Roberto Klein BazZy Huan Son Alejandro Cruz Paz Kirk Bushell Alex Yao Cheng Romain Goyet kev_the_dev Danny Hiemstra Anton cj Julia Lovel Greg Bell Ellin Tolstov
Marco S

for custom buisness logics. eg.

  • wizards
  • complex forms
  • statistics
  • reports
  • combined searches
  • and much more
Philippe Creux
Collaborator

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

Marco S

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

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

Philippe Creux
Collaborator

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?

Philippe Creux
Collaborator

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

Marco S

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
Joseph Jaramillo

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

Andreas Korth

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

Lukas Rieder

+1

Philippe Creux
Collaborator
Robin Wenglewski

+1

Matthieu Barthel

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

Robin Wunderlin

+1

Roberto Klein

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

BazZy

Absolutely needed feature, is it planned?
+1

Huan Son

whatever

+1 :D

Alejandro Cruz Paz

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

Kirk Bushell

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

Romain Goyet

+1

Anton

+1 agree! definitly need this feature.

cj
cj commented

+1

Julia Lovel

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

Huan Son
Julia Lovel

@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

Huan Son
Greg Bell
Owner

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

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

Greg Bell gregbell closed this
Ellin Tolstov

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?

Philippe Creux
Collaborator

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

Ellin Tolstov

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.

Robin Wunderlin

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

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

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

Robin Wunderlin

Did not find a better solution..

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.