zorab47 / active_admin-sortable_tree

Show ActiveAdmin index as a nested tree with drag'n'drop
MIT License
163 stars 127 forks source link

Comparison of Integer with String failed #61

Closed EnziinSystem closed 7 years ago

EnziinSystem commented 7 years ago

My environment :

-Ruby 2.4.0

-Rails 5.0.1

ArgumentError in Admin::Tasks#index

Showing /home/kevin/.rvm/gems/ruby-2.4.0/bundler/gems/activeadmin-6463e2b717b2/app/views/active_admin/resource/index.html.arb where line #2 raised:

comparison of Integer with String failed

    @collection = @collection.sort_by do |a|
      a.send(options[:sorting_attribute]) || 1
    end
    @resource_name = active_admin_config.resource_name.to_s.underscore.parameterize('_')

error

zorab47 commented 7 years ago

Do your Task records respond to the sorting attribute defined? Can you provide a sample of how the ActiveAdmin resource file is defined? What is your hierarchy library, Ancestry?

EnziinSystem commented 7 years ago

Hi,

I edited source code to :

@collection = @collection.sort_by do |a|
          *(a.send(options[:sorting_attribute])).to_i || 1*
        end
        @resource_name =
active_admin_config.resource_name.to_s.underscore.parameterize('_')

And it's work!.

zorab47 commented 7 years ago

Does your sorting field in the database contain nils or non-numeric values?

zorab47 commented 7 years ago

Any updates here? @EnziinSystem

EnziinSystem commented 7 years ago

Hello,

This is my model

class CreateTasks < ActiveRecord::Migration[5.0]
  def change
    create_table :tasks do |t|
      t.string :title
      t.text :content
      t.string :video
      t.boolean :header, :null => false, :default => false
      t.string :tag
      t.references :courses, index: true, foreign_key: true
      t.string :slug
      t.timestamps
    end
  end
end

I am sorting the "tag" field, it's string type and it can null.

ActiveAdmin.register Task do
  permit_params :title, :content, :video_length, :video, :video_embed, :subtitle,
                :data_file, :header, :tag, :course_id, :slug

  sortable tree: false, sorting_attribute: :tag

  index :as => :sortable do
    label :title

    actions
  end
...
zorab47 commented 7 years ago

This is dependent on the library providing the sortable functionality. What library are you using?

zorab47 commented 7 years ago

I'll close this for now. Please re-open this issue if needed.

EnziinSystem commented 7 years ago

Now, I need add "active_admin_sortable_index_eval.rb" in config/initializers.

p1 p2

Please fix :

    @collection = @collection.sort_by do |a|
      a.send(options[:sorting_attribute]) || 1
    end

To :

    @collection = @collection.sort_by do |a|
      (a.send(options[:sorting_attribute])).to_i || 1
    end
EnziinSystem commented 7 years ago

Sorry for my mismatch.

In my "Task" model, the attribute "tag" is a string, it must be an integer type.

Close issue.