SPA

SPA using Ember

Convert app to single page application usning ember

As per the suggestions of the Sylvain Abelar I have started reading the documentation of both the methods (OPAL and SPA using ember). Then we discuss the cons and pros of both the methods and finalize that we should convert our application to single page application then make it work offline.

SPA using ember

SPA in Ember (backend in Rails, frontend in Ember and the frontend asks for data in JSON calls). Ember will store some data in the frontend, you can probable tell it to fetch more (to work offline) and to store it in LocalStorage.

Now for embedding the ember in rails we have two methods. These are:

  • ember-rails
  • ember-cli-rails

ember-rails: ember-rails will help us write ember with rails, that gem will probably go into production.

ember-cli-rails: ember-cli-rails is a set of tools to help us build the app, we will probably install it but not run it in production.

Implementing the ember in the rails

Step1: Create new app in rails and remove the Turbolinks from the following places:

  • Gemfile
  • Application Javascript (app/assets/javascripts/application.js)
  • Layout (app/views/layouts/application.html.erb)

Step2 Add the following gems in our Gemfile and run bundle install.

gem 'ember-rails'
gem 'ember-source', '~> 1.8.1'
gem 'emblem-rails'

Step3: Create the basic structure of our app using following command:

For Javascript:

rails g ember:bootstrap -n App --javascript-engine js

If you want the generated files to use CoffeeScript then add a flag:

rails g ember:bootstrap -n App --javascript-engine coffee

Step 4: Set the environment of the application:

# config/environments/test.rb
  config.ember.variant = :development

# config/environments/development.rb
 config.ember.variant = :development

# config/environments/production.rb
 config.ember.variant = :production

Now make the changes in the application according to the requirement and making ember work with the rails.

Following are the some links for reference:

Written on August 11, 2016