Ruby on Rails
Getting Started with Ruby on Rails
This quickstart demonstrates how to add our PhotoEditor SDK for HTML to a Ruby on Rails application in no time. Just follow the steps and you'll get a fully fledged photo editor in your rails app.
WARNING: The repository is not meant as a fully fledged Rails application, but as a base for further development instead.
Integration#
Init Rails
rails new pesdk-rails-democd pesdk-rails-demoGet PhotoEditor HTML5
export VERSION=4.22.1wget "https://github.com/imgly/pesdk-html5-build/archive/v$VERSION.zip"unzip -x "v$VERSION.zip"with curl
export VERSION=4.22.1curl -O -L "https://github.com/imgly/pesdk-html5-build/archive/v$VERSION.zip"unzip -x "v$VERSION.zip"Copy files to vendor directory
mkdir -p vendor/assets/javascriptscp "pesdk-html5-build-$VERSION/js/PhotoEditor"* vendor/assets/javascriptscp "pesdk-html5-build-$VERSION/js/vendor/"* vendor/assets/javascriptsmkdir -p vendor/assets/stylesheetscp "pesdk-html5-build-$VERSION/css/PhotoEditor"* vendor/assets/stylesheetsmkdir -p vendor/assets/imagescp -R "pesdk-html5-build-$VERSION/assets/"* vendor/assets/imagesCreate new home controller with index page
rails generate controller home indexOpen
app/views/home/index.html.erb
<!-- PESDK Demo Integration --><divid="pesdk"style="width: 100vmin; height: 75vmin; padding: 0px; margin: 0px"></div>Update
app/assets/javascripts/application.js
...//= require react.production.min//= require react-dom.production.min//= require PhotoEditorSDK.min//= require PhotoEditorSDK.UI.ReactUI.min...Update
app/assets/stylesheets/application.css
```css...*= require PhotoEditorSDK.UI.ReactUI.min...*/```Important: Insert the code snipped before the
*/
Edit
app/assets/javascripts/home.coffee
and insertwindow.onload = ->license = 'license-string' // <-- Please replace this with the content of your license file. The JSON-object must be in string format.container = document.getElementById('pesdk')editor = new (PhotoEditorSDK.UI.ReactUI)(container: containerlicense: licenseassets:baseUrl: '/assets'resolver: (path) ->path)returnIf you don't want to use CoffeeScript, delete
app/assets/javascripts/home.coffee
, createapp/assets/javascripts/home.js
and insertwindow.onload = function () {license = 'license-string'; // <-- Please replace this with the content of your license file. The JSON-object must be in string format.var container = document.getElementById('pesdk');var editor = new PhotoEditorSDK.UI.ReactUI({container: container,license: license,assets: {baseUrl: '/assets', // => Matches default asset url for railsresolver: function (path) {return path;},},});};Start rails
bundle exec rails server -p 3000Open Webbrowser and go to
http://localhost:3000/home/index
Switch between React- and DesktopUI#
In order to use the DesktopUI instead of the ReactUI, you need to make some changes to your setup. Replace in point ...
//= require PhotoEditorSDK.UI.ReactUI.min
with//= require PhotoEditorSDK.UI.DesktopUI.min
*= require PhotoEditorSDK.UI.ReactUI.min
with*= require PhotoEditorSDK.UI.DesktopUI.min
editor = new (PhotoEditorSDK.UI.ReactUI)
witheditor = new (PhotoEditorSDK.UI.DesktopUI)
inhome.coffee
orvar editor = new PhotoEditorSDK.UI.ReactUI
withvar editor = new PhotoEditorSDK.UI.DesktopUI
inhome.js