RailsAdminSortEmbedded
Sort for Embedded documents in mongoid. Field order is need.
Bonus features:
- special case support for
cover
andimage
columns
Installation
Add this line to your application's Gemfile:
gem 'rails_admin_sort_embedded', :github => 'ack43/rails_admin_sort_embedded'
And then execute:
$ bundle
Usage with rails_admin
Add the sort_embedded action for each model or only for models you need
RailsAdmin.config do |config|
config.actions do
......
do
visible do
%w(Page).include? bindings[:abstract_model].model_name
end
end
end
end
In embedded model:
field :order, type: Integer, default: 0
scope :sorted, -> { order_by([:order, :asc]) } #optional
In parent model:
:method_name
rails_admin do ...
({
fields: [:method_name],
toggle_fields: [:enabled],
thumbnail_fields: [:image, :cover],
thumbnail_size: :thumb,
thumbnail_gem: :paperclip, # or :carrierwave
})
end
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Credits
Some ideas and code for this gem are taken from: