Skip to content

Instantly share code, notes, and snippets.

@loicginoux
Last active July 1, 2023 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loicginoux/ad00be79cd2f315ff832b63685320064 to your computer and use it in GitHub Desktop.
Save loicginoux/ad00be79cd2f315ff832b63685320064 to your computer and use it in GitHub Desktop.
Integrate Bootsy rich text editor with rails admin

Gemfile

gem "rails_admin"
gem 'bootsy'

/app/assets/javascripts/rails_admin/custom/ui.js

# load bootsy after a page change, not just after loading a new page
//= require bootsy
$(document).on('pjax:end', Bootsy.init);

/app/assets/stylesheets/rails_admin/custom/theming.css.scss:

@import "bootsy";

/app/models/YOUR_MODEL.rb

rails_admin do
  edit do
    field :content do
      render do
        bindings[:view].render :partial => "bootsy_news_content_field", :locals => {:field => self, :form => bindings[:form]}
      end
    end   
  end
  show do
    field :content do
      formatted_value do
        value.html_safe
      end
    end
  end
end

/app/views/rails_admin/main/_bootsy_news_content_field.html.slim:

= form.bootsy_area :content, class: 'form-control', rows: 15,  editor_options: { alert_unsaved: false }

config/routes.rb

mount Bootsy::Engine => '/bootsy', as: 'bootsy'

config/initializers/bootsy.rb

# Use this setup block to configure all options available in Bootsy.
Bootsy.setup do |config|
  # Default editor options
  #   You can also override them locally by passing an
  #   editor_options hash to bootsy_area
  # config.editor_options = {
  #   font_styles: true,
  #   emphasis: true,
  #   lists: true,
  #   html: false,
  #   link: true,
  #   image: true,
  #   color: true
  # }
  #
  # Image versions available
  #  Possible values: :small, :medium, :large and/or :original
  config.image_versions_available = [:small, :medium, :large, :original]
  #
  #
  # SMALL IMAGES
  #
  # Width limit for small images
  config.small_image[:width] = 160
  #
  # Height limit for small images
  config.small_image[:height] = 160
  #
  #
  # MEDIUM IMAGES
  #
  # Width limit for medium images
  config.medium_image[:width] = 360
  #
  # Height limit for medium images
  config.medium_image[:height] = 360
  #
  #
  # LARGE IMAGES
  #
  # Width limit for large images
  config.large_image[:width] = 760
  #
  # Height limit for large images
  config.large_image[:height] = 760
  #
  #
  # Whether user can destroy uploaded files
  config.allow_destroy = true
  #
  #
  # Storage mode
  #   You can change the sorage mode below from :file to :fog if you want
  #   to use Amazon S3 and other cloud services. If you do that, please add
  #   'fog' to your Gemfile and create and configure your credentials in an
  #   initializer file, as described in Carrierwave's docs:
  #   https://github.com/carrierwaveuploader/carrierwave#using-amazon-s3
  # config.storage = :file
  #
  #
  # Store directory (inside 'public') for storage = :file
  #   BE CAREFUL! Changing this may break previously uploaded file paths!
  # config.store_dir = 'uploads'
  #
  #
  # Specify the controller to inherit from. Using ApplicationController
  # allows you to perform authentication from within your app.
  # config.base_controller = ActionController::Base
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment