Oliver Oliver - 4 months ago 13
Ruby Question

Undefined method "reorder" for #<Array:0xbc38600> using ActiveAdmin

I have a problem with ActiveAdmin using Ruby ruby 1.9.2p290 and Ruby on Rails 3.2.1.

I used this wiki page to setup the resource for the AdminUsers that works perfectly: Your First Admin Resource: AdminUser

After that I wanted to create the resource for my project model. The migrations for that looks like this:

class CreateProjects < ActiveRecord::Migration
def change
create_table :projects do |t|
t.string :name
t.text :description
t.boolean :isactive

t.timestamps
end
end
end

class AddSlugToProjects < ActiveRecord::Migration
def change
add_column :projects, :slug, :string
add_index :projects, :slug
end
end


My project model:

class Project < ActiveRecord::Base

scope :isactive, :conditions => ["isactive = ?",true]

extend FriendlyId
friendly_id :name, use: [:slugged, :history]

attr_accessible :name, :description, :isactive

end


And that's the project_controller:

class ProjectsController < ApplicationController

def index
#
# @projects gets filled in application_controller to be always
# available for the twitter bootstrap navbar
# @projects = Project.isactive.find(:all, :order => 'LOWER(name) asc')
#
end

def show
@project = Project.isactive.find(params[:id])
if request.path != project_path(@project)
redirect_to @project, :status => :moved_permanently
end
end

end


The admin/projects.rb is currently 'empty'

ActiveAdmin.register Project do
end


And after all that, everything I get is the following error:

Started GET "/admin/projects" for 192.168.0.2 at 2012-02-21 20:58:49 +0100
Processing by Admin::ProjectsController#index as HTML
Project Load (0.1ms) SELECT "projects".* FROM "projects" WHERE (isactive = 't') ORDER BY LOWER(name) asc
AdminUser Load (0.1ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = 2 LIMIT 1
Rendered /home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.1/app/views/active_admin/resource/index.html.arb (11.7ms)
Completed 500 Internal Server Error in 54ms

ActionView::Template::Error (undefined method `reorder' for #<Array:0xa3ecd44>):
1: render renderer_for(:index)
activeadmin (0.4.1) lib/active_admin/views/pages/index.rb:41:in `items_in_collection?'
activeadmin (0.4.1) lib/active_admin/views/pages/index.rb:20:in `main_content'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:116:in `block (2 levels) in build_main_content_wrapper'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:68:in `block in build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:96:in `with_current_dom_context'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:67:in `build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:77:in `insert_tag'
activeadmin (0.4.1) lib/active_admin/arbre/html/element.rb:17:in `div'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:115:in `block in build_main_content_wrapper'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:68:in `block in build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:96:in `with_current_dom_context'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:67:in `build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:77:in `insert_tag'
activeadmin (0.4.1) lib/active_admin/arbre/html/element.rb:17:in `div'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:114:in `build_main_content_wrapper'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:98:in `block in build_page_content'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:68:in `block in build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:96:in `with_current_dom_context'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:67:in `build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:77:in `insert_tag'
activeadmin (0.4.1) lib/active_admin/arbre/html/element.rb:17:in `div'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:97:in `build_page_content'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:41:in `block (2 levels) in build_page'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:68:in `block in build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:96:in `with_current_dom_context'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:67:in `build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:77:in `insert_tag'
activeadmin (0.4.1) lib/active_admin/arbre/html/element.rb:17:in `div'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:38:in `block in build_page'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:96:in `with_current_dom_context'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:37:in `build_page'
activeadmin (0.4.1) lib/active_admin/views/pages/base.rb:10:in `build'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:63:in `build_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:77:in `insert_tag'
activeadmin (0.4.1) lib/active_admin/arbre/builder.rb:41:in `method_missing'
activeadmin (0.4.1) lib/active_admin/view_helpers/renderer_helper.rb:21:in `render'
activeadmin (0.4.1) app/views/active_admin/resource/index.html.arb:1:in `__home_eins____rbenv_versions_______p____lib_ruby_gems_______gems_activeadmin_______app_views_active_admin_resource_index_html_arb___523541447_100786690'
actionpack (3.2.1) lib/action_view/template.rb:143:in `block in render'
activesupport (3.2.1) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.1) lib/action_view/template.rb:141:in `render'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:41:in `block (2 levels) in render_template'
actionpack (3.2.1) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.1) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:40:in `block in render_template'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:48:in `render_with_layout'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:39:in `render_template'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:12:in `render'
actionpack (3.2.1) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.1) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:109:in `_render_template'
actionpack (3.2.1) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.1) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.1) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.1) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.1) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
activesupport (3.2.1) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.1) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:39:in `render'
activeadmin (0.4.1) lib/active_admin/resource_controller/actions.rb:13:in `block (2 levels) in index'
actionpack (3.2.1) lib/action_controller/metal/responder.rb:229:in `call'
actionpack (3.2.1) lib/action_controller/metal/responder.rb:229:in `default_render'
actionpack (3.2.1) lib/action_controller/metal/responder.rb:160:in `to_html'
responders (0.6.5) lib/responders/flash_responder.rb:93:in `to_html'
actionpack (3.2.1) lib/action_controller/metal/responder.rb:153:in `respond'
actionpack (3.2.1) lib/action_controller/metal/responder.rb:146:in `call'
actionpack (3.2.1) lib/action_controller/metal/mime_responds.rb:238:in `respond_with'
inherited_resources (1.3.0) lib/inherited_resources/actions.rb:7:in `index'
activeadmin (0.4.1) lib/active_admin/resource_controller/actions.rb:11:in `index'
actionpack (3.2.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.1) lib/active_support/callbacks.rb:469:in `_run__639476650__process_action__1068992826__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
activerecord (3.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.1) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `dispatch'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:30:in `call'
journey (1.0.1) lib/journey/router.rb:68:in `block in call'
journey (1.0.1) lib/journey/router.rb:56:in `each'
journey (1.0.1) lib/journey/router.rb:56:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:589:in `call'
sass (3.1.15) lib/sass/plugin/rack.rb:54:in `call'
warden (1.1.1) lib/warden/manager.rb:35:in `block in call'
warden (1.1.1) lib/warden/manager.rb:34:in `catch'
warden (1.1.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.1) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__471556791__call__937320005__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.2.1) lib/rails/engine.rb:479:in `call'
railties (3.2.1) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'


Rendered /home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (5.1ms)
Rendered /home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.1ms)
Rendered /home/eins11/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (9.8ms)


And I have no idea what the problem is...

Answer

Ah, I've found the solution. I don't know exactly why the error happened but I had to change my application_controller.

In the application_controller I fetched all projects to @projects:

before_filter :getActiveProjects

protected

  def getActiveProjects
    @projects = Project.isactive.find(:all, :order => 'LOWER(name) asc')
  end

That was confusing ActiveAdmin. After I changed that to

before_filter :getActiveProjects

protected

  def getActiveProjects
    @projects_all = Project.isactive.find(:all, :order => 'LOWER(name) asc')
  end

and projects_controller index action to

def index
  @projects = @projects_all
end

everything worked fine ;)