Extracting model configuration
# app/models/booking.rb
class Booking
include RailsAdmin::Booking
end
# app/models/concerns/rails_admin/booking.rb
module RailsAdmin::Booking
extend ActiveSupport::Concern
included do
rails_admin do
navigation_label 'Booking'
end
end
end
# config/initializers/rails_admin.rb
# You need to whitelist the model
config.included_models = ['Booking']
Add Multiple Photos Upload
- For example, to add multiple images to a product
# Product model
has_many :images, dependent: :destroy
accepts_nested_attributes_for :images, allow_destroy: true,
reject_if: :all_blank
# Image model
class Image < ActiveRecord::Base
belongs_to :product, inverse_of: :images
has_attached_file :photo,
whiny: false,
default_url: "/images/:style/missing.png",
default_style: :normal,
styles: { normal: '210x110>' }
end
Delete Paperclip Images
# In your model
# where you have has_attached_file :image
attr_accessor :delete_image
before_validation { self.image.clear if self.delete_image == '1' }
Fieldsets
module RailsAdmin::Ship
extend ActiveSupport::Concern
included do
rails_admin do
object_label_method :name
navigation_label 'Ships'
weight -100
edit do
include_all_fields
exclude_fields :categories, :cabins
group :deck do
label "Deck Info"
active false
field :deck_image
end
group :dining do
label "Dining Info"
active false
field :dining_info, :wysihtml5
end
group :images do
label "Photo Gallery"
active false
field :images do
active true
end
end
end
end
end
end
Nested form ordering
- You want to order your accepts_nested_attributes nested form:
# At the file of the nested model
class Product::Image
default_scope order :row_order # this will be picked up by RA to order
end