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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With