0
votes

I have a ruby site setup and had Active Admin working for all my admin pages. All of a sudden one admin categories page is producing the error below. The category is the top level of the relationships in the database. I have checked everything from column name references, making sure I have the relationships defined properly, and the database setup properly. I am sure the /app/admin/category.rb is fine as well. At this point I am not sure if this is actually an issue with my code but a gem issue. Any help in the right direction would be greatly appreciated!

NoMethodError in Admin::Categories#index

Showing /usr/local/rvm/gems/ruby-2.3.0/gems/activeadmin-1.0.0.pre2/app/views/active_admin/resource/index.html.arb where line #2 raised:

undefined method `except' for #<String:0x000000051298f0>
Did you mean?  exec

Extracted source (around line #2):

  insert_tag renderer_for(:index)

Rails.root: /var/www/apps/swss
Application Trace | Framework Trace | Full Trace

activeadmin (1.0.0.pre2) lib/active_admin/helpers/collection.rb:7:in `collection_size'
activeadmin (1.0.0.pre2) lib/active_admin/helpers/collection.rb:13:in `collection_is_empty?'
activeadmin (1.0.0.pre2) lib/active_admin/views/pages/index.rb:45:in `items_in_collection?'
activeadmin (1.0.0.pre2) lib/active_admin/views/pages/index.rb:49:in `build_collection'
activeadmin (1.0.0.pre2) lib/active_admin/views/pages/index.rb:28:in `block in main_content'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.3) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:14:in `batch_action_form'
activeadmin (1.0.0.pre2) lib/active_admin/views/pages/index.rb:36:in `wrap_with_batch_action_form'
activeadmin (1.0.0.pre2) lib/active_admin/views/pages/index.rb:26:in `main_content'
activeadmin (1.0.0.pre2) lib/active_admin/views/pages/base.rb:91:in `block (2 levels) in build_main_content_wrapper'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.3) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:14:in `div'
activeadmin (1.0.0.pre2) lib/active_admin/views/pages/base.rb:90:in `block in build_main_content_wrapper'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.3) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:14:in `div'
activeadmin (1.0.0.pre2) lib/active_admin/views/pages/base.rb:89:in `build_main_content_wrapper'
activeadmin (1.0.0.pre2) lib/active_admin/views/pages/base.rb:75:in `block in build_page_content'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.3) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:14:in `div'
activeadmin (1.0.0.pre2) lib/active_admin/views/pages/base.rb:74:in `build_page_content'
activeadmin (1.0.0.pre2) lib/active_admin/views/pages/base.rb:52:in `block (2 levels) in build_page'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.3) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:14:in `div'
activeadmin (1.0.0.pre2) lib/active_admin/views/pages/base.rb:48:in `block in build_page'
arbre (1.0.3) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
activeadmin (1.0.0.pre2) lib/active_admin/views/pages/base.rb:47:in `build_page'
activeadmin (1.0.0.pre2) lib/active_admin/views/pages/base.rb:10:in `build'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:30:in `block in build_tag'
arbre (1.0.3) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.3) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
activeadmin (1.0.0.pre2) app/views/active_admin/resource/index.html.arb:2:in `block in __usr_local_rvm_gems_ruby_______gems_activeadmin_______pre__app_views_active_admin_resource_index_html_arb___4208362892031437948_70086151104600'
arbre (1.0.3) lib/arbre/context.rb:45:in `instance_eval'
arbre (1.0.3) lib/arbre/context.rb:45:in `initialize'
activeadmin (1.0.0.pre2) app/views/active_admin/resource/index.html.arb:1:in `new'
activeadmin (1.0.0.pre2) app/views/active_admin/resource/index.html.arb:1:in `__usr_local_rvm_gems_ruby_______gems_activeadmin_______pre__app_views_active_admin_resource_index_html_arb___4208362892031437948_70086151104600'
actionview (4.1.10) lib/action_view/template.rb:145:in `block in render'
activesupport (4.1.10) lib/active_support/notifications.rb:161:in `instrument'
actionview (4.1.10) lib/action_view/template.rb:339:in `instrument'
actionview (4.1.10) lib/action_view/template.rb:143:in `render'
actionview (4.1.10) lib/action_view/renderer/template_renderer.rb:55:in `block (2 levels) in render_template'
actionview (4.1.10) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (4.1.10) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.1.10) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.1.10) lib/active_support/notifications.rb:159:in `instrument'
actionview (4.1.10) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionview (4.1.10) lib/action_view/renderer/template_renderer.rb:54:in `block in render_template'
actionview (4.1.10) lib/action_view/renderer/template_renderer.rb:62:in `render_with_layout'
actionview (4.1.10) lib/action_view/renderer/template_renderer.rb:53:in `render_template'
actionview (4.1.10) lib/action_view/renderer/template_renderer.rb:17:in `render'
actionview (4.1.10) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (4.1.10) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (4.1.10) lib/action_view/rendering.rb:99:in `_render_template'
actionpack (4.1.10) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (4.1.10) lib/action_view/rendering.rb:82:in `render_to_body'
actionpack (4.1.10) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
actionpack (4.1.10) lib/action_controller/metal/renderers.rb:32:in `render_to_body'
actionpack (4.1.10) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (4.1.10) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.1.10) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
activesupport (4.1.10) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
activesupport (4.1.10) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.1.10) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
actionpack (4.1.10) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
activerecord (4.1.10) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.1.10) lib/action_controller/metal/instrumentation.rb:43:in `render'
actionpack (4.1.10) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.1.10) lib/action_controller/metal/responder.rb:238:in `default_render'
actionpack (4.1.10) lib/action_controller/metal/responder.rb:165:in `to_html'
responders (1.1.2) lib/responders/flash_responder.rb:107:in `to_html'
actionpack (4.1.10) lib/action_controller/metal/responder.rb:158:in `respond'
actionpack (4.1.10) lib/action_controller/metal/responder.rb:151:in `call'
actionpack (4.1.10) lib/action_controller/metal/mime_responds.rb:400:in `respond_with'
inherited_resources (1.6.0) lib/inherited_resources/actions.rb:7:in `index'
activeadmin (1.0.0.pre2) lib/active_admin/resource_controller/streaming.rb:12:in `index'
actionpack (4.1.10) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.1.10) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.1.10) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.1.10) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.1.10) lib/active_support/callbacks.rb:113:in `call'
activesupport (4.1.10) lib/active_support/callbacks.rb:552:in `block (2 levels) in compile'
activesupport (4.1.10) lib/active_support/callbacks.rb:502:in `call'
activesupport (4.1.10) lib/active_support/callbacks.rb:86:in `run_callbacks'
actionpack (4.1.10) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.1.10) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.1.10) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.1.10) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.1.10) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.1.10) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.1.10) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.1.10) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.1.10) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.1.10) lib/abstract_controller/base.rb:136:in `process'
actionview (4.1.10) lib/action_view/rendering.rb:30:in `process'
actionpack (4.1.10) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.1.10) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.1.10) lib/action_controller/metal.rb:232:in `block in action'
actionpack (4.1.10) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
actionpack (4.1.10) lib/action_dispatch/routing/route_set.rb:50:in `call'
actionpack (4.1.10) lib/action_dispatch/journey/router.rb:73:in `block in call'
actionpack (4.1.10) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.1.10) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.1.10) lib/action_dispatch/routing/route_set.rb:692:in `call'
warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
warden (1.2.6) lib/warden/manager.rb:34:in `catch'
warden (1.2.6) lib/warden/manager.rb:34:in `call'
rack (1.5.5) lib/rack/etag.rb:23:in `call'
rack (1.5.5) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.5) lib/rack/head.rb:11:in `call'
actionpack (4.1.10) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.1.10) lib/action_dispatch/middleware/flash.rb:254:in `call'
rack (1.5.5) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.5) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.1.10) lib/action_dispatch/middleware/cookies.rb:562:in `call'
activerecord (4.1.10) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.1.10) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
activerecord (4.1.10) lib/active_record/migration.rb:380:in `call'
actionpack (4.1.10) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.10) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.10) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.10) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.10) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.1.10) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.1.10) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.10) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.10) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.10) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.10) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.10) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.10) lib/rails/rack/logger.rb:20:in `call'
request_store (1.3.1) lib/request_store/middleware.rb:9:in `call'
actionpack (4.1.10) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.5) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.10) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
actionpack (4.1.10) lib/action_dispatch/middleware/static.rb:84:in `call'
rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
railties (4.1.10) lib/rails/engine.rb:514:in `call'
railties (4.1.10) lib/rails/application.rb:144:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
rack (1.5.5) lib/rack/content_length.rb:14:in `call'
rack (1.5.5) lib/rack/handler/webrick.rb:60:in `service'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'

Request

Parameters:

None

Toggle session dump

_csrf_token: "TNSus5W+3uX5ILYOWiOKfHwAHlNhdhalaBIAF0WFXss="
session_id: "d876e40840760d2b6be3d6b608ca8a22"
warden.user.user.key: [[1], "$2a$10$B0niQfE1OtB0smU3Uz.aOe"]

Toggle env dump

GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
HTTP_ACCEPT_ENCODING: "gzip, deflate"
HTTP_ACCEPT_LANGUAGE: "en-US,en;q=0.5"
HTTP_CACHE_CONTROL: "max-age=0"
REMOTE_ADDR: "71.68.78.10"
REMOTE_HOST: "71.68.78.10"
SERVER_NAME: "www.swshotguns.com"
SERVER_PROTOCOL: "HTTP/1.1"

Response

Headers:

None

enter image description here

My /app/models/category.rb file

class Category < ActiveRecord::Base
  has_many :products
  accepts_nested_attributes_for :products
end

my /app/admin/category.rb file

ActiveAdmin.register Category do

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

  form do |f|
    f.inputs "Product Category" do
      f.input :name
      f.input :description
      ###########################################################################
      ## Create a collection to produce a dropdown based on the category table ##
      ###########################################################################
      #f.input :parent, collection: Category.all => Category.all.map{|c| [c.name, c.id]}
    end
  f.actions
  end
end

My Gemfile

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.10'
# Use mysql as the database for Active Record
gem 'mysql'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'

##################
##Custom Entries##
##################
gem 'activeadmin', '~> 1.0.0.pre2'
gem 'rails-erd'
#gem 'devise', ' ~> 3.2'
gem 'devise'
gem 'cancancan' # or cancancan
gem 'draper'
gem 'pundit'
gem 'paperclip'
gem 'ckeditor'


# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
#gem 'spring',        group: :development

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

ERD Screen Shot

enter image description here

/usr/local/rvm/gems/ruby-2.3.0/gems/activeadmin-1.0.0.pre2/app/views/active_admin/resource/index.html.arb

insert_tag renderer_for(:index)
2
paste this app/views/active_admin/resource/index.html.arb - Mukesh
@Mukesh I apended it to the end of my post. - The Gugaru
please, paste code which is rendering . (index partial) - Mukesh
@Mukesh no code is rendered just the error message in the first code block in my post I will provide a screen shot as well. - The Gugaru

2 Answers

1
votes

Ok I figured this out! For others that may have similar issues in the future.

For starters my Category table was being used to generate the navigation for the site and because of that I had a before_filter in my application controller:

class ApplicationController < ActionController::Base
  include NaviGenerator

  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  before_filter :getCategories

  private
  def getCategories
    @categories = categoryListGen 'nav'
  end
end

I am not sure as of why and I am digging further, however something about querying the categories to generate the navigation before Active Admin was loading was causing a collision of some sort and I discovered this via Better Errors gem and Binding Of Caller gem. This showed the navigation code being generated before Active Admin loaded thus causing the error. So I fixed it by doing:

class ApplicationController < ActionController::Base
  include NaviGenerator

  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  before_filter :getCategories

  private
  def getCategories
    cururl = request.original_url
    cururl.to_s
    if cururl.include? "admin"
      ##Dont run navi code!
    else
      @categories = categoryListGen 'nav'
    end
  end
end

I have simulated this in different fashions quickly and it seems that if you have a before_filter that runs and sets a global variable and you use active admin, it will cause the models that said method uses to not load when accessing related Active Admin pages.

I am not sure if this is a bug and I will have to dig more to find out the exact cause. However for the time being doing a test against the current url to see if it includes the string admin you can at least have bliss on both front and back end when using Active Admin.

-1
votes

What I think you want is to add config.skip_before_action :getCategories to your ActiveAdmin initizializer