Dwijen
Dwijen

Reputation: 590

Rails - ActiveAdmin not showing new Resources in Menu

I am using ActiveAdmin with Rails 4 and Grape.

I am creating new AA resources with rails g active_admin:resource ModelClassName it used to work fine. Every resource showed up as a Menu Link in the Admin Console.

But now for some reason, for the new Models that I am creating, Active Admin is not showing the resources for the same in the Menu.

Any leads to why this could happen would help a lot.

Ruby Version - 2.2.3

Rails Version - 4.2.4

Active Admin Version - 1.0.0

This is my GemFile

ruby '2.2.3'
gem 'rails', '4.2.4'
gem 'pg'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
# gem 'bcrypt', '~> 3.1.7'
# gem 'unicorn'
# gem 'capistrano-rails', group: :development

group :development, :test do
debugger console
  gem 'byebug'
end

group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

gem 'devise'
gem 'activeadmin', github: 'activeadmin'
gem 'grape'
gem 'cancan'
gem 'jwt'
gem 'aws-sdk', '~> 2'
gem 'rmagick'
gem 'grape-swagger'

EDIT The new Model resource doesn't work. But if i rename the Model in the same file to some older model it shows up fine.

Generated ActiveAdmin resource file -

ActiveAdmin.register NewModel do # DOESN'T WORK AND DOESN'T SHOW UP IN MENU

    # See permitted parameters documentation:
    # https://github.com/activeadmin/activeadmin/blob/master/docs/2 resource-    customization.md#setting-up-strong-parameters
    #
    # permit_params :list, :of, :attributes, :on, :model
    #
    # or
    #
    # permit_params do
    #   permitted = [:permitted, :attributes]
    #   permitted << :other if resource.something?
    #   permitted
    # end

end

ActiveAdmin.register OldModel, :as => 'Some Name' do # WORKS AND SHOWS UP IN MENU

    # See permitted parameters documentation:
    # https://github.com/activeadmin/activeadmin/blob/master/docs/2 resource-    customization.md#setting-up-strong-parameters
    #
    # permit_params :list, :of, :attributes, :on, :model
    #
    # or
    #
    # permit_params do
    #   permitted = [:permitted, :attributes]
    #   permitted << :other if resource.something?
    #   permitted
    # end

end

Upvotes: 2

Views: 2666

Answers (2)

Nagendra Rao
Nagendra Rao

Reputation: 7152

If you are using CanCan gem with your ActiveAdmin, your models folder will have a <proj-name>_admin_ability.rb file, where you need to add your new model to can :manage (or :read) list.

include CanCan::Ability

def initialize(user)
    can :manage, [User, ModelClassName]
end

Upvotes: 6

Olalekan Sogunle
Olalekan Sogunle

Reputation: 2357

Yes the new resource could be prevented from showing by an authorization adapter. It could be CanCan or Pundit or any other Authorization system configured with Active Admin.

You can get the specific authorization scheme your active admin is using from config/initializers/active_admin.rb

on the line that reads config.authorization_adapter = ActiveAdmin::Adapter

After getting your Authorization Adapter, you will want to add the new resource to the proper Admin Authorization. Pundit for example, you will want to crate a new policy for the resource allowing an Admin User to carry out specific actions.

Upvotes: 3

Related Questions