BlackDolphin
BlackDolphin

Reputation: 111

Active Admin - non resource related Controller

Hy there, i try to implement a own controller into active admin + it would neet to inherit the footer / header / breadcrumbs of active admin

i need a own template file for the regular index action ... passing a parameter in to show related stats ( i would render them in the template using google chart api)

the issue i came accross is there is no way todo that from scratch expect sidebars which wont help me alot ..

i need to display like 7 different charts on that view

i realy appreciate any idea since it drives me insane

thanks Pierre

Upvotes: 4

Views: 2466

Answers (2)

Jonathan Williams
Jonathan Williams

Reputation: 306

Further to the previous answer. You don't even need to define a real model (in your models folder). The minimum code I needed to get this working was:

All in the one file: app/admin/charts.rb

class Chart < ActiveRecord::Base
end

ActiveAdmin.register Chart do
  config.comments = false
  config.clear_action_items!
  before_filter do @skip_sidebar = true end


  controller do
    def index
      params[:action] = "Google Charts" # this sets the page title (so it doesnt just render 'index')
      render 'admin/charts/index', :layout => 'active_admin' # renders the index view in app/views/admin/charts
    end
  end
end

I used it for this gist: https://gist.github.com/1644526

Upvotes: 3

Sjors Branderhorst
Sjors Branderhorst

Reputation: 2182

This is what worked for me, just substitute the right name for ViewLogger in the codeblocks. This way you wont have to create a dummy table in your database.

Make a file /app/models/viewlogger.rb with this contents, for more advanced tableless models you might want to check out http://keithmcdonnell.net/activerecord_tableless_model_gem.html or google your own insight together.

class Viewlogger < ActiveRecord::Base

  def self.columns 
    @columns ||= []
  end

  # ...  

end

add an entry to /config/initializers/inflections.rb

ActiveSupport::Inflector.inflections do |inflect|
  inflect.uncountable %w( viewlogger )
end

set up a route for your viewlogger, in config/routes.rb:

match '/admin/viewlogger' => 'admin/viewlogger#index', :as => :admin_viewlogger

now you can formulate the activeadmin register block as follows (make you sure you create a view partial in the right place)

ActiveAdmin.register Viewlogger do
  config.comments = false
  before_filter do @skip_sidebar = true end
  # menu false
  config.clear_action_items!   # this will prevent the 'new button' showing up


  controller do
    def index
      # some hopefully useful code
      render 'admin/viewlogger/index', :layout => 'active_admin'
    end
  end   

end

Upvotes: 2

Related Questions