Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActionView::Template::Error (undefined method `name' for #<Array:0x9df61d>): #2433

Closed
chenghung opened this issue Aug 22, 2013 · 8 comments
Closed

Comments

@chenghung
Copy link

I got below template error when I visit index page with default template

ruby & rails Environment
jruby 1.7.4 (1.9.3p392)
rails 4.0.0
activeadmin (0.6.0 72a9c30)  <-  rails4 branch
ActiveAdmin.register Tk::User do

  actions :all, except: [:destroy]
  filter :ID
  index do
    selectable_column
    column :ID
    column :NickName

    default_actions
  end

end

edit & show work well but index doesn't
Is it compatible problem with rails 4 ?
Can anyone help me ?

ActionView::Template::Error (undefined method `name' for #&lt;Array:0x9df61d&gt;):
    1: insert_tag renderer_for(:index)
  activerecord (4.0.0) lib/active_record/model_schema.rb:210:in `columns'
  org/jruby/RubyHash.java:1332:in `each'
  org/jruby/RubyEnumerable.java:713:in `map'
  activerecord (4.0.0) lib/active_record/model_schema.rb:208:in `columns'
  activerecord (4.0.0) lib/active_record/model_schema.rb:247:in `column_names'
  activerecord (4.0.0) lib/active_record/relation/calculations.rb:229:in `aggregate_column'
  activerecord (4.0.0) lib/active_record/relation/calculations.rb:390:in `build_count_subquery'
  activerecord (4.0.0) lib/active_record/relation/calculations.rb:250:in `execute_simple_calculation'
  activerecord (4.0.0) lib/active_record/relation/calculations.rb:224:in `perform_calculation'
  activerecord (4.0.0) lib/active_record/relation/calculations.rb:108:in `calculate'
  activerecord-deprecated_finders (1.0.3) lib/active_record/deprecated_finders/relation.rb:84:in `calculate'
  activerecord (4.0.0) lib/active_record/relation/calculations.rb:24:in `count'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/helpers/collection.rb:11:in `collection_size'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/helpers/collection.rb:19:in `collection_is_empty?'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/index.rb:44:in `items_in_collection?'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/index.rb:48:in `build_collection'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/index.rb:27:in `main_content'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `build_tag'
  arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:18:in `batch_action_form'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/index.rb:35:in `wrap_with_batch_action_form'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/index.rb:25:in `main_content'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/base.rb:83:in `build_main_content_wrapper'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `build_tag'
  arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:18:in `div'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/base.rb:82:in `build_main_content_wrapper'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `build_tag'
  arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:18:in `div'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/base.rb:81:in `build_main_content_wrapper'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/base.rb:65:in `build_page_content'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `build_tag'
  arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:18:in `div'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/base.rb:64:in `build_page_content'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/base.rb:47:in `build_page'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `build_tag'
  arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:18:in `div'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/base.rb:44:in `build_page'
  arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/base.rb:43:in `build_page'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/base.rb:10:in `build'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:30:in `build_tag'
  arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/app/views/active_admin/resource/index.html.arb:1:in `__usr_local_rvm_gems_jruby_______tk_bundler_gems_active_admin___a_c__cef___app_views_active_admin_resource_index_html_arb__1339939714_11860'
  org/jruby/RubyBasicObject.java:1735:in `instance_eval'
  arbre (1.0.1) lib/arbre/context.rb:45:in `initialize'
  /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/app/views/active_admin/resource/index.html.arb:1:in `__usr_local_rvm_gems_jruby_______tk_bundler_gems_active_admin___a_c__cef___app_views_active_admin_resource_index_html_arb__1339939714_11860'
  org/jruby/RubyBasicObject.java:1715:in `__send__'
  org/jruby/RubyKernel.java:2217:in `send'
  actionpack (4.0.0) lib/action_view/template.rb:143:in `render'
  activesupport (4.0.0) lib/active_support/notifications.rb:161:in `instrument'
  actionpack (4.0.0) lib/action_view/template.rb:141:in `render'
  actionpack (4.0.0) lib/action_view/renderer/template_renderer.rb:49:in `render_template'
  actionpack (4.0.0) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
  activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
  activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
@seanlinsley
Copy link
Contributor

Could you try using MRI Ruby? I've never run into this problem.

Otherwise, it would be great if you could throw up a test Rails app that has this problem so I can try debugging it.

@chenghung
Copy link
Author

hi Daxter, MRI Ruby (2.0.0-p247) also run into problems

 Rendered /usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/active_admin-72a9c30cef47/app/views/active_admin/resource/index.html.arb (39.7ms)
Completed 500 Internal Server Error in 45ms

ActionView::Template::Error (undefined method `name' for #<Array:0xb4a05fc8>):
    1: insert_tag renderer_for(:index)
  activerecord (4.0.0) lib/active_record/model_schema.rb:210:in `block in columns'
  activerecord (4.0.0) lib/active_record/model_schema.rb:208:in `each'
  activerecord (4.0.0) lib/active_record/model_schema.rb:208:in `map'
  activerecord (4.0.0) lib/active_record/model_schema.rb:208:in `columns'
  activerecord (4.0.0) lib/active_record/model_schema.rb:247:in `column_names'
  activerecord (4.0.0) lib/active_record/relation/calculations.rb:229:in `aggregate_column'
  activerecord (4.0.0) lib/active_record/relation/calculations.rb:390:in `build_count_subquery'
  activerecord (4.0.0) lib/active_record/relation/calculations.rb:250:in `execute_simple_calculation'
  activerecord (4.0.0) lib/active_record/relation/calculations.rb:224:in `perform_calculation'
  activerecord (4.0.0) lib/active_record/relation/calculations.rb:108:in `calculate'
  activerecord-deprecated_finders (1.0.3) lib/active_record/deprecated_finders/relation.rb:84:in `calculate'
  activerecord (4.0.0) lib/active_record/relation/calculations.rb:24:in `count'
  /usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/helpers/collection.rb:11:in `collection_size'
  /usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/helpers/collection.rb:19:in `collection_is_empty?'
  /usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/index.rb:44:in `items_in_collection?'
  /usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/index.rb:48:in `build_collection'
  /usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/index.rb:27:in `block in main_content'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
  arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:14:in `batch_action_form'
  /usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/index.rb:35:in `wrap_with_batch_action_form'
  /usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/index.rb:25:in `main_content'
  /usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/base.rb:83:in `block (2 levels) in build_main_content_wrapper'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
  arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:14:in `div'
  /usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/views/pages/base.rb:82:in `block in build_main_content_wrapper'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'

@chenghung
Copy link
Author

I have traced the source code of active_record and active_admin and saw a deprecation warning

DEPRECATION WARNING: call columns with a table name!. (called from collection_size at /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/helpers/collection.rb:11)

I am not sure if problem raised by deprecation API


active_record


#### activerecord-4.0.0/lib/active_record/model_schema.rb

  # Returns an array of column objects for the table associated with this class.
  def columns
    @columns ||= connection.schema_cache.columns(table_name).map do |col|
      col = col.dup
      Rails.logger.debug "---------- (#{table_name}) ------------"
      Rails.logger.debug col.inspect if col.is_a? Array                                                                                            
      Rails.logger.debug "*** #{col.class}"
      Rails.logger.debug "*** #{col.name}"
      col.primary = (col.name == primary_key)           ##  <----   error raised here
      col 
    end 
  end 

active admin

active_admin-72a9c30cef47/lib/helpers/collection.rb

  def collection_size(collection=collection)
    size = collection.reorder("").count
    # when GROUP BY is used, AR returns Hash instead of Fixnum for .size
    size = size.size if size.kind_of?(Hash)

    size
  end

output


---------- (user) ------------
*** ActiveRecord::ConnectionAdapters::MysqlAdapter::Column
*** CreatedAt
---------- (user) ------------
*** ActiveRecord::ConnectionAdapters::MysqlAdapter::Column
*** UpdatedAt
---------- (user) ------------
*** ActiveRecord::ConnectionAdapters::MysqlAdapter::Column
*** LoginAt
DEPRECATION WARNING: call columns with a table name!. (called from collection_size at /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/lib/active_admin/helpers/collection.rb:11)
---------- () ------------
["schema_migrations", [#<ActiveRecord::ConnectionAdapters::MysqlAdapter::Column:0x16c54b7 @coder=nil, @precision=nil, @name="version", @default=nil, @scale=nil, @type=:string, @limit=255, @primary=nil, @null=false, @sql_type="varchar(255)">]]
*** Array
Rendered /usr/local/rvm/gems/jruby-1.7.4@tk/bundler/gems/active_admin-72a9c30cef47/app/views/active_admin/resource/index.html.arb (3484.0ms)
Completed 500 Internal Server Error in 6120ms

@chenghung chenghung reopened this Aug 23, 2013
@wbyoung
Copy link

wbyoung commented Sep 27, 2013

I'm having the same problem with Rails 4.

@wbyoung
Copy link

wbyoung commented Sep 27, 2013

Tracked this down to an issue with using a base class on the model. This seems to be a problem in Rails 4.

@seanlinsley
Copy link
Contributor

Thanks for the context @wbyoung

@wbyoung
Copy link

wbyoung commented Sep 27, 2013

I worked around this by patching Kaminari if anyone's interested. I think this can be closed here since the issue isn't in Active Admin.

@seanlinsley
Copy link
Contributor

Okay, I'm going to close this. Thanks again @wbyoung

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants