Closed EnziinSystem closed 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?
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!.
Does your sorting field in the database contain nil
s or non-numeric values?
Any updates here? @EnziinSystem
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
...
This is dependent on the library providing the sortable functionality. What library are you using?
I'll close this for now. Please re-open this issue if needed.
Now, I need add "active_admin_sortable_index_eval.rb" in config/initializers.
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
Sorry for my mismatch.
In my "Task" model, the attribute "tag" is a string, it must be an integer type.
Close issue.
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