Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveAdmin how to add a custom controller without model [duplicate]

Possible Duplicate:
Add page to active admin

I currently looking to a solution for adding a controller without a model to the admin generate by ActiveAdmin (and Rails 3.1). Of course I'd like to add a new menu in the navbar.

Using ActiveAdmin.register MyControllerWithoutModel do isn't working.

Edit : This question is a duplicate of Add page to active admin but no answer found.

like image 794
brunto Avatar asked Nov 04 '22 13:11

brunto


1 Answers

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

like image 100
Sjors Branderhorst Avatar answered Nov 09 '22 04:11

Sjors Branderhorst