Неопределенный метод "изменить порядок" для #используя ActiveAdmin - PullRequest
9 голосов
/ 22 февраля 2012

У меня проблема с ActiveAdmin, использующим Ruby ruby ​​1.9.2p290 и Ruby on Rails 3.2.1.

Я использовал эту вики-страницу для настройки ресурса AdminUsers, который работает отлично: Your FirstРесурс администратора: AdminUser

После этого я хотел создать ресурс для моей модели проекта.Миграции для этого выглядят так:

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

Модель моего проекта:

class Project < ActiveRecord::Base

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

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

  attr_accessible :name, :description, :isactive

end

И это контроллер проекта:

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

Администратор / projects.rbв настоящее время 'пусто'

ActiveAdmin.register Project do  
end

И после всего, что я получаю, это следующая ошибка:

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)

И я понятия не имею, в чем проблема ...

Ответы [ 3 ]

12 голосов
/ 22 февраля 2012

Ах, я нашел решение. Я не знаю точно, почему произошла ошибка, но мне пришлось изменить свой application_controller.

В application_controller я загрузил все проекты в @projects:

before_filter :getActiveProjects

protected

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

Это сбивало с толку ActiveAdmin. После того, как я изменил это на

before_filter :getActiveProjects

protected

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

и действие индекса_проектов_контроллера на

def index
  @projects = @projects_all
end

все работало нормально;)

3 голосов
/ 05 октября 2013

Более простое решение - просто пропустить фильтр в конкретном активном административном контроллере:

ActiveAdmin.register Project do  
    controller do
      skip_before_filter :getActiveProjects
    end
end
0 голосов
/ 28 июля 2016

Активный администратор производит специальную обработку @resource переменных. Где resource - соответствующее имя класса, переданное методу регистрации. Так для кода:

ActiveAdmin.register Project do  
end

имя переменной

`@project`

Мы не должны присваивать значение переменной с таким именем. Также такие переменные могут быть объектом класса ActiveRecord :: Relation. И то, как @Oliver пишет имя как @projects_all - хороший выбор. Использование skip_before_filter также решает проблему.

Одну хитрую вещь нужно проверить. Контроллер ресурса может не иметь никаких фильтров. Контроллер ресурса может вообще не существовать. Какое имя фильтра нужно поместить в skip_before_filter? А где такие фильтры? Контроллер приложения по умолчанию используется в любом случае. Фильтр может быть установлен на главном контроллере приложения. Сообщение об ошибке этой проблемы вообще не информативно. Поэтому необходимо проверить контроллер приложения на наличие установленных фильтров.

...