No release in over 3 years
Low commit activity in last 3 years
Image manager for RailsAdmin and CKEditor.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

Runtime

~> 4.2, >= 4.2.3
>= 1.0.0.alpha.4
>= 0.17.0, < 2.0
~> 5.1, >= 5.1.0
~> 5.0, >= 5.0.2
~> 1.1, >= 1.1.1
 Project Readme

RailsAdmin_ImageManager

Image manager for RailsAdmin and CKEditor.

Installation

  1. Add this line to your application's Gemfile:
gem 'rails_admin_image_manager'
  1. Run
$ bundle install
  1. Install RailsAdmin_ImageManager
$ rails generate rails_admin_image_manager:install
  1. Add the upload filepath to your .gitignore file
/public/rails_admin_image_manager
  1. Run migrations
$ rails db:migrate SCOPE=rails_admin_image_manager
  1. Install the image manager CKEditor plugin
mkdir -p app/assets/javascripts/ckeditor && touch app/assets/javascripts/ckeditor/config.js.erb
echo "//= require 'rails_admin_image_manager/ckeditor_plugin'" | cat - app/assets/javascripts/ckeditor/config.js.erb > temp && mv temp app/assets/javascripts/ckeditor/config.js.erb
  1. If you need to add the image manager button in a custom CKEditor config
CKEDITOR.editorConfig = function( config )
{
  config.toolbar =  [
    [ 'Styles', 'Bold', 'Italic', 'Underline' ],
    [ 'imageManager']
  ];
}

Configuration

  1. The mount RailsAdminImageManager::Engine route must appear before the mount RailsAdmin::Engine route in the app routes.rb file.

  2. If you need to explicitly specified the Files and Tags sections in RailsAdmin:

RailsAdmin.config do |config|
  config.actions do
    index do
      only ['RailsAdminImageManager::Tag', 'RailsAdminImageManager::File']
    end
  end
end

Authentication and authorization

The gem uses the RailsAdmin authentication and authorization methods.

Usage

Create the image foreign key in your db:

class CreateImageForeignKey < ActiveRecord::Migration[5.0]
  def change
    change_table :mymodel do |t|
      t.integer :image_manager_file_id
    end
    add_foreign_key :mymodel, :image_manager_files, on_update: :cascade, on_delete: :restrict
  end
end

Add the image relationship to your model:

class Mymodel < ApplicationRecord
  # has_managed_file :attribute_name, :attribute_id, :options
  has_managed_file :image_manager_file, :image_manager_file_id, mandatory: false
end

Add the image picker in RailsAdmin:

config.model Mymodel do
  edit do
    field :image_manager_file_id, :image_manager_picker do
      config({
        hidden_input: true,
        paginates_per: 10
      }) # Optionnal
    end
  end
end

To display the image in a Rails template:

<img src="<%= image_url @mymodel.image_manager_file.image.dynamic_url('100x100') %>">

Development

Assets

When developping for the gem, assets need to be watch/compile. We are running a webpack/gulp setup ; to run it, just npm run start at gem's root

Authors

  • Mario Bouchard
  • Louis-Philippe Dumas

License

The gem is available as open source under the terms of the MIT License.