rmce_uploadr

Here’s a scenario this gem is suitable for.

You have multiple rack/sinatra/rails CMS-like apps where a page editing is done with TinyMCE. You want all of them use the same storage / database for image manipulation.

This gem uses Sinatra, ActiveRecord and Paperclip.

Install

For this gem to work you have to put your TinyMCE javascripts in public/javascripts/tiny_mce.

1. Install the gem

  • add config.gem "rmce_uploadr" to environment.rb and run sudo rake gems:install

  • add gem "rmce_uploadr" to Gemfile if your using Bundler and run bundle install

2. Set RMceUploadr::App as a middleware

  • for a rails app add the following inside Rails::Initializer.run block:

    config.middleware.use "RMceUploadr::App" do |app|
      # configuration according to ActiveRecord::Base.establish_connection
      app.dbconf = {:adapter => 'sqlite3', 
                    :database => File.join(File.dirname(__FILE__), '..', '..', 'shared', 'db.sqlite3')}
      app.settings.set :cdn_host, "http://localhost:3000"
    end
    
  • almost the same if you’re a rack/sinatra app:

    use ::RMceUploadr::App do |app|
      # configuration according to ActiveRecord::Base.establish_connection
      app.dbconf = {:adapter => 'sqlite3', 
                    :database => root_path('..', 'shared', 'db.sqlite3')}
    end
    

cdn_host is an optional parameter. Useful when you host your images through another domain. Having this set will result in images src attribute be an absolute URL, otherwise image URLs will be something like “/public/uploads/g/images/…”

3. Add plugin loading to TinyMCE init function, e.g.

<script type="text/javascript" charset="utf-8">
  // Initialize TinyMCE with rmce_uploadr plugin and inlinepopups
  tinyMCE.init({
      plugins: "rmce_uploadr,inlinepopups",
      mode : "textareas",
      theme : "advanced",
      dialog_type: 'modal',
      theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,bullist,numlist,undo,redo,link,unlink,image",
      theme_advanced_buttons2 : "",
      theme_advanced_buttons3 : "",
      theme_advanced_toolbar_location : "top",
      theme_advanced_toolbar_align : "left",
      theme_advanced_statusbar_location : "bottom"
  });
</script>

Notice plugins: "rmce_uploadr" and theme_advanced_buttons1: "image" (which you probably have already).

4. You’re done

Uploaded files will live in public/uploads/g/images/:id_partition/:style_:filename so you probably want public/uploads/g/ to be shared accross all your apps.

5. Check out rails and sinatra examples

examples/rails and examples/sinatra are setup to work with examples/shared/db.sqlite3 and examples/shared/uploads directory.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 alex. See LICENSE for details.