我有一个ruby网站设置,并且我的所有管理页面都有Active Admin。突然之间,一个管理类别页面产生了以下错误。该类别是数据库中关系的顶级。 我检查了列名引用的所有内容,确保正确定义了关系,并正确设置了数据库。我确信/app/admin/category.rb也没关系。在这一点上,我不确定这是否实际上是我的代码的问题,但宝石问题。任何正确方向的帮助将不胜感激!
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
我的/app/models/category.rb文件
class Category < ActiveRecord::Base
has_many :products
accepts_nested_attributes_for :products
end
我的/app/admin/category.rb文件
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
我的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屏幕截图
/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)
答案 0 :(得分:0)
好的,我想出来了!对于将来可能会遇到类似问题的其他人。
对于初学者,我的Category表用于生成网站的导航,因此我的应用程序控制器中有一个before_filter:
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
我不确定为什么和我正在进一步挖掘,但是在Active Admin加载之前查询类别以生成导航的某些事情导致了某种类型的碰撞,我通过Better Errors gem和Caller的绑定发现了这一点宝石。这表明导航代码在Active Admin加载之前生成,从而导致错误。所以我通过这样做来修复它:
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
我已经以不同的方式快速模拟了这一点,看起来如果你有一个运行并设置全局变量的before_filter并且你使用了主动管理员,它将导致在访问相关的Active Admin时所述方法使用的模型无法加载页。
我不确定这是否是一个错误,我将不得不挖掘更多来找出确切的原因。但是,当前正在对当前网址进行测试以查看它是否包含字符串admin时,使用Active Admin时,前端和后端至少都有幸福。
答案 1 :(得分:-1)
我认为您想要的是将config.skip_before_action :getCategories
添加到您的ActiveAdmin initizializer