Git Product home page Git Product logo

ember-cli-rails's Introduction

Ember CLI Rails

Unify your EmberCLI and Rails Workflows!

EmberCLI-Rails is designed to give you the best of both worlds:

  • Stay up to date with the latest JavaScript technology and EmberCLI addons
  • Develop your Rails API and Ember front-ends from within a single process
  • Inject Rails-generated content into your EmberCLI application
  • Avoid Cross-Origin Resource Sharing gotchas by serving your EmberCLI applications and your API from a single domain
  • Write truly end-to-end integration tests, exercising your application's entire stack through JavaScript-enabled Capybara tests
  • Deploy your entire suite of applications to Heroku with a single git push

If you're having trouble, checkout the example project!

EmberCLI-Rails Supports EmberCLI 1.13.13 and later.

Install

Add the following to your Gemfile:

gem "ember-cli-rails"

Then run bundle install:

$ bundle install

If you haven't created an Ember application yet, generate a new one:

$ ember new frontend --skip-git

Setup

First, generate the gem's initializer:

$ rails generate ember:init

This will create the following initializer:

# config/initializers/ember.rb

EmberCli.configure do |c|
  c.app :frontend
end

This initializer assumes that your Ember application exists in Rails.root.join("frontend").

If this is not the case, you could

  • move your existing Ember application into Rails.root.join("frontend")
  • configure frontend to reference the Ember application in its current directory:
c.app :frontend, path: "~/projects/my-ember-app"

Initializer options

  • name - this represents the name of the Ember CLI application.

  • path - the path where your Ember CLI application is located. The default value is the name of your app in the Rails root.

  • silent - this provides --silent option for Ember CLI commands to control verbosity of their output.

  • yarn - enables the yarn package manager when installing dependencies

EmberCli.configure do |c|
  c.app :adminpanel # path defaults to `Rails.root.join("adminpanel")`
  c.app :frontend,
    path: "/path/to/your/ember-cli-app/on/disk"
  c.app :payments, silent: true # by default it's false
end

Next, install the ember-cli-rails-addon:

$ cd path/to/frontend
$ ember install ember-cli-rails-addon

Be sure that the addon's MAJOR and MINOR version matches the gem's MAJOR and MINOR versions.

For instance, if you're using the 0.6.x version of the gem, specify ~> 0.6.0 in your Ember app's package.json:

{
  "devDependencies": {
    "ember-cli-rails-addon": "~> 0.6.0"
  }
}

Mount

Configure Rails to route requests to the frontend Ember application:

# config/routes.rb

Rails.application.routes.draw do
  mount_ember_app :frontend, to: "/"
end

Routing options

  • to - The path to handle as an Ember application. This will only apply to format: :html requests. Additionally, this will handle child routes as well. For instance, mounting mount_ember_app :frontend, to: "/frontend" will handle a format: :html request to /frontend/posts. Note: If you specify a custom path, you must also update the rootURL in frontend/config/environment.js. See Mounting multiple Ember applications for more information.
  • controller - Defaults to "ember_cli/ember"
  • action - Defaults to "index"

Finally, install your Ember application's dependencies:

$ rake ember:install

Boot your Rails application, navigate to "/", and view your EmberCLI application!

Develop

EmberCLI Rails exposes several useful rake tasks.

ember:install

Install the Ember applications' dependencies.

ember:compile

Compile the Ember applications.

ember:test

Execute Ember's test suite.

If you're using Rake to run the test suite, make sure to configure your test task to depend on ember:test.

For example, to configure a bare rake command to run both RSpec and Ember test suites, configure the default task to depend on both spec and ember:test.

task default: [:spec, "ember:test"]

Deploy

When Rails is running in production mode, EmberCLI-Rails stops doing runtime compilation. Instead, configured apps are built during rake assets:precompile. This keeps things quick for end users, and extends the normal Rails asset building process.

Configuration information, including instructions for Heroku and Capistrano, can be found below.

CDN

In production environments, assets should be served over a Content Delivery Network.

Configuring an ember-cli-rails application to serve Ember's assets over a CDN is very similar to configuring an EmberCLI application to serve assets over a CDN:

var app = new EmberApp({
  fingerprint: {
    prepend: 'https://cdn.example.com/'
  }
});

If you're serving the Ember application from a path other than "/", the prepend URL must end with the mounted path:

var app = new EmberApp({
  fingerprint: {
    // for an Ember application mounted to `/admin_panel/`
    prepend: 'https://cdn.example.com/admin_panel/',
  }
});

As long as your CDN is configured to pull from your Rails application , your assets will be served over the CDN.

Deployment Strategies

By default, EmberCLI-Rails uses a file-based deployment strategy that depends on the output of ember build.

Using this deployment strategy, Rails will serve the index.html file and other assets that ember build produces.

These EmberCLI-generated assets are served with the same Cache-Control headers as Rails' other static files:

# config/environments/production.rb
Rails.application.configure do
  # serve static files with cache headers set to expire in 1 year
  config.static_cache_control = "public, max-age=31622400"
end

If you need to override this behavior (for instance, if you're using ember-cli-deploy's "Lightning Fast Deployment" strategy in production), you can specify the strategy's class in the initializer:

EmberCli.configure do |config|
  config.app :frontend, deploy: { production: EmberCli::Deploy::Redis }
end

This example configures the frontend Ember application to retrieve the index's HTML from an ember-cli-deploy-redis -populated Redis entry using the ember-cli-rails-deploy-redis gem.

If you're deploying HTML with a custom strategy in development or test, disable EmberCLI-Rails' build step by setting ENV["SKIP_EMBER"] = true.

NOTE:

Specifying a deployment strategy is only supported for applications that use the mount_ember_app and render_ember_app helpers.

Heroku

To configure your EmberCLI-Rails applications for Heroku:

  1. Execute rails generate ember:heroku.
  2. Commit the newly generated files.
  3. Add the NodeJS buildpack and configure NPM to include the bower dependency's executable file (if your build process requires bower).
$ heroku buildpacks:clear
$ heroku buildpacks:add --index 1 heroku/nodejs
$ heroku buildpacks:add --index 2 heroku/ruby
$ heroku config:unset SKIP_EMBER

You are ready to deploy:

$ git push heroku master

EmberCLI compilation happens at deploy-time, triggered by the asset:precompile rake task.

NOTE Run the generator each time you introduce additional EmberCLI applications into the project.

Slug size

Heroku slug size is limited. The build process creates artifacts that are not necessary for the server to run, but are included in the deployed Heroku slug.

Omitting these build assets can dramatically reduce slug size.

A build-pack solution for this is discussed in Issue #491.

Capistrano

EmberCLI-Rails executes both npm install and bower install during EmberCLI's compilation, triggered by the asset:precompile rake task.

The npm and bower executables are required to be defined in the deployment SSH session's $PATH. It is not sufficient to modify the session's $PATH in a .bash_profile.

To resolve this issue, prepend the Node installation's bin directory to the target system's $PATH:

#config/deploy/production.rb

set :default_env, {
  "PATH" => "/home/deploy/.nvm/versions/node/v4.2.1/bin:$PATH"
}

The system in this example is using nvm to configure the node version. If you're not using nvm, make sure the string you prepend to the $PATH variable contains the directory or directories that contain the bower and npm executables.

For faster deployments

Place the following in your deploy/<environment>.rb

set :linked_dirs, %w{<ember-app-name>/node_modules <ember-app-name>/bower_components}

to avoid rebuilding all the node modules and bower components with every deploy. Replace <ember-app-name> with the name of your ember app (default is frontend).

Override

By default, routes defined by ember_app will be rendered with the internal EmberCli::EmberController.

Overriding the view

The EmberCli::EmberController renders the Ember application's index.html and injects the Rails-generated CSRF tags into the <head>.

To customize the view, create app/views/ember_cli/ember/index.html.erb:

<%= render_ember_app ember_app do |head| %>
  <% head.append do %>
    <%= csrf_meta_tags %>
  <% end %>
<% end %>

The ember_app helper is available within the EmberCli::EmberController's view, and refers to the name of the current EmberCLI application.

To inject the EmberCLI generated index.html, use the render_ember_app helper in your view:

<!-- app/views/application/index.html.erb -->
<%= render_ember_app :frontend do |head, body| %>
  <% head.append do %>
    <%= csrf_meta_tags %>
  <% end %>

  <% body.append do %>
    <%= render partial: "my-analytics" %>
  <% end %>
<% end %>

The body block argument and the corresponding call to body.append in the example are both optional, and can be omitted.

Serving Rails-generated CSS

For more information on how to work with EmberCLI-generated stylesheets, refer to the Stylesheets section. EmberCLI-generated CSS will be embedded in the response's HTML document by default.

To serve assets generated and served by Rails, inject them into the document's <head>:

<%= render_ember_app :frontend do |head| %>
  <% head.append do %>
    <%= stylesheet_link_tag "application" %>
    <%= csrf_meta_tags %>
  <% end %>
<% end %>

There are no technical limitations to sharing assets between the Ember client and the Rails server, but picking one or the other might simplify the project's organization.

Sharing code during asset compilation is not possible.

For example, Ember's SCSS files cannot use @import directives referencing Rails' SCSS modules.

Overriding the controller

To override this behavior, you can specify [any of Rails' routing options] route-options.

For the sake of this example, override the controller and action options:

# config/routes.rb

Rails.application.routes.draw do
  mount_ember_app :frontend, to: "/", controller: "application", action: "index"
end

When serving the EmberCLI generated index.html with the render_ember_app helper, make sure the controller's layout is disabled, as EmberCLI generates a fully-formed HTML document:

# app/controllers/application.rb
class ApplicationController < ActionController::Base
  def index
    render layout: false
  end
end

Rendering the EmberCLI generated JS and CSS

Rendering EmberCLI applications with render_ember_app is the recommended, actively supported method of serving EmberCLI applications.

However, for the sake of backwards compatibility, ember-cli-rails supports injecting the EmberCLI-generated assets into an existing Rails layout.

Following the example above, configure the mounted EmberCLI application to be served by a custom controller (ApplicationController, in this case).

In the corresponding view, use the asset helpers:

<%= include_ember_script_tags :frontend %>
<%= include_ember_stylesheet_tags :frontend %>

Mounting multiple Ember applications

Rendering Ember applications to paths other than / requires additional configuration.

Consider a scenario where you had Ember applications named frontend and admin_panel, served from / and /admin_panel respectively.

First, specify the Ember applications in the initializer:

EmberCli.configure do |c|
  c.app :frontend
  c.app :admin_panel, path: "path/to/admin_ember_app"
end

Next, mount the applications alongside the rest of Rails' routes. Note that admin_panel route is added before the frontend route because it's more specific:

# /config/routes.rb
Rails.application.routes.draw do
  mount_ember_app :admin_panel, to: "/admin_panel"
  mount_ember_app :frontend, to: "/"
end

Then set each Ember application's rootURL to the mount point:

// frontend/config/environment.js

module.exports = function(environment) {
  var ENV = {
    modulePrefix: 'frontend',
    environment: environment,
    rootURL: '/',
    // ...
  }
};

// path/to/admin_ember_app/config/environment.js

module.exports = function(environment) {
  var ENV = {
    modulePrefix: 'admin_panel',
    environment: environment,
    rootURL: '/admin_panel',  // originally '/'
    // ...
  }
};

Finally, configure EmberCLI's fingerprinting to prepend the mount point to the application's assets:

// frontend/ember-cli-build.js

module.exports = function(defaults) {
  var app = new EmberApp(defaults, {
    fingerprint: {
      // matches the `/` mount point
      prepend: 'https://cdn.example.com/',
    }
  });
};


// path/to/admin_ember_app/ember-cli-build.js

module.exports = function(defaults) {
  var app = new EmberApp(defaults, {
    fingerprint: {
      // matches the `/admin_panel` mount point
      prepend: 'https://cdn.example.com/admin_panel/',
    }
  });
};

When injecting the EmberCLI-generated assets with the include_ember_script_tags and include_ember_stylesheet_tags helpers to a path other than "/", a <base> tag must also be injected with a corresponding href value:

<base href="/">
<%= include_ember_script_tags :frontend %>
<%= include_ember_stylesheet_tags :frontend %>

<base href="/admin_panel/">
<%= include_ember_script_tags :admin_panel %>
<%= include_ember_stylesheet_tags :admin_panel %>

If you're using the include_ember style helpers with a single-page Ember application that defers routing to the Rails application, insert a call to mount_ember_assets at the bottom of your routes file to serve the EmberCLI-generated assets:

# config/routes.rb
Rails.application.routes.draw do
  mount_ember_assets :frontend, to: "/"
end

CSRF Tokens

Your Rails controllers, by default, expect a valid authenticity token to be submitted along with non-GET requests.

Without the authenticity token, requests will respond with 422 Unprocessable Entity errors (specifically ActionController::InvalidAuthenticityToken).

To add the necessary tokens to requests, inject the csrf_meta_tags into the template:

<!-- app/views/application/index.html.erb -->
<%= render_ember_app :frontend do |head| %>
  <% head.append do %>
    <%= csrf_meta_tags %>
  <% end %>
<% end %>

The default EmberCli::EmberController and the default view handle behave like this by default.

If an Ember application is mounted with another controller, it should append the CSRF tags to its view's <head>.

ember-cli-rails-addon configures your Ember application to make HTTP requests with the injected CSRF tokens in the X-CSRF-TOKEN header.

Serving from multi-process servers in development

If you're using a multi-process server (Puma, Unicorn, etc.) in development, make sure it's configured to run a single worker process.

Without restricting the server to a single process, it is possible for multiple EmberCLI runners to clobber each others' work.

SKIP_EMBER

If set on the environment, SKIP_EMBER will configure ember-cli-rails to skip the build step entirely. This is useful if you're using an alternative deployment strategy in the test or development environment. By default, ember-cli-rails will skip the build step in production-like environments.

EMBER_ENV

If set on the environment, the value of EMBER_ENV will be passed to the ember process as the value of the --environment flag.

If EMBER_ENV is unspecified, the current Rails environment will be passed to the ember process, with the exception of non-standard Rails environments, which will be replaced with production.

RAILS_ENV

While being managed by EmberCLI Rails, EmberCLI process will have access to the RAILS_ENV environment variable. This can be helpful to detect the Rails environment from within the EmberCLI process.

This can be useful to determine whether or not EmberCLI is running in its own standalone process or being managed by Rails.

For example, to enable ember-cli-mirage API responses in development while being run outside of Rails (while run by ember serve), check for the absence of the RAILS_ENV environment variable:

// config/environment.js
if (environment === 'development') {
  ENV['ember-cli-mirage'] = {
    enabled: typeof process.env.RAILS_ENV === 'undefined',
  }
}

RAILS_ENV will be absent in production builds.

EmberCLI support

This project supports:

  • EmberCLI versions >= 1.13.13

Ruby and Rails support

This project supports:

  • Ruby versions >= 2.5.0
  • Rails versions >=5.2.x.

To learn more about supported versions and upgrades, read the upgrading guide.

Contributing

See the CONTRIBUTING document. Thank you, contributors!

License

Open source templates are Copyright (c) 2015 thoughtbot, inc. It contains free software that may be redistributed under the terms specified in the LICENSE file.

About

ember-cli-rails was originally created by Pavel Pravosud and Jonathan Jackson.

ember-cli-rails is maintained by Sean Doyle and Jonathan Jackson.

About thoughtbot

thoughtbot

This repo is maintained and funded by thoughtbot, inc. The names and logos for thoughtbot are trademarks of thoughtbot, inc.

We love open source software! See our other projects. We are available for hire.

ember-cli-rails's People

Contributors

botandrose-machine avatar breckenedge avatar dchersey avatar drcapulet avatar egh avatar f1sherman avatar harisadam avatar iheanyi avatar jeanbono avatar jesenko avatar krasnoukhov avatar maksimabramchuk avatar mbackermann avatar mhaylock avatar ndbroadbent avatar nruth avatar pootsbook avatar rondale-sc avatar rwjblue avatar rwz avatar samselikoff avatar samsinite avatar seanpdoyle avatar sevos avatar smolnar avatar stevehanson avatar thcrock avatar thewatts avatar tricknotes avatar wireframe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ember-cli-rails's Issues

brittle assumptions about rails environment names

As things stand, if you use any non-standard development environment names, there is no good way to have them use the development mode in ember-cli-rails, because ember-cli-rails makes hardcoded assumptions about the names of Rails environments:

https://github.com/rwz/ember-cli-rails/blob/master/lib/ember-cli/helpers.rb#L25
https://github.com/rwz/ember-cli-rails/blob/master/lib/ember-cli/middleware.rb#L18

It seems to me that there any time there are checks like these, there ought to be a config option to override the defaults. @rwz, would you be open to a PR along those lines?

Asset precompile does not include ember assets

I'm not sure if this is an issue or maybe just a documentation issue.

This gem works great in development, but when I precompile for production, it does not include the ember assets.

Is there an undocumented trick to get precompilation to work? I appreciate any help you can provide :)

Can't precompile assets

Env:
Jruby 1.7.18
Rails 4.1.7
ember-cli-rials 0.1.1

When running

RAILS_ENV=production RACK_ENV=production bin/rake assets:precompile

I'm getting:

mkmf.rb can't find header files for ruby at /Users/nadav/.rbenv/versions/jruby-1.7.18/lib/native/include/ruby/ruby.h

`rake assets:precompile` does not work in production environment

These are the steps I've taken:

$ rails new ember-cli
$ bundle install # with ember-cli-rails added
$ cd app
$ ember new frontend
$ npm install --save-dev ember-cli-rails-addon
$ cd ../..
$ rails generate ember-cli:init

If you precompile the assets in the development env, everything seems to work:

$ rake assets:precompile
I, [2014-12-24T14:03:30.893996 #50624]  INFO -- : Writing ~/ember-cli-rails/public/assets/application-3b98198579ac9fca1f421d7e2627581f.js
I, [2014-12-24T14:03:30.931184 #50624]  INFO -- : Writing ~/ember-cli-rails/public/assets/application-f1f7fd9c1e6b8d058b9c675550f9ebea.css
I, [2014-12-24T14:03:30.935022 #50624]  INFO -- : Writing ~/ember-cli-rails/public/assets/frontend/failed-547acef100bc282b96dc64e8b6604b06.png
I, [2014-12-24T14:03:30.939737 #50624]  INFO -- : Writing ~/ember-cli-rails/public/assets/frontend/frontend-99e6c4d79ad8ec1acdf86eac47c1b7fa.css
I, [2014-12-24T14:03:30.945031 #50624]  INFO -- : Writing ~/ember-cli-rails/public/assets/frontend/frontend-9572a4495113884f4d8de57e948a06c3.js
I, [2014-12-24T14:03:30.948075 #50624]  INFO -- : Writing ~/ember-cli-rails/public/assets/frontend/passed-b5e38ca83da4e4ea09b180d1faba7bfa.png
I, [2014-12-24T14:03:30.952094 #50624]  INFO -- : Writing ~/ember-cli-rails/public/assets/frontend/test-loader-315fc12a5d61ea5c864156647be45423.js
I, [2014-12-24T14:03:30.956582 #50624]  INFO -- : Writing ~/ember-cli-rails/public/assets/frontend/test-support-7cf2dfe8b514795401e82c4e19508f1d.css
I, [2014-12-24T14:03:30.963422 #50624]  INFO -- : Writing ~/ember-cli-rails/public/assets/frontend/test-support-9f23aa18d7200303afc55b3870220d1c.js
I, [2014-12-24T14:03:30.972688 #50624]  INFO -- : Writing ~/ember-cli-rails/public/assets/frontend/vendor-069e88c06b889877799890854d7f4c40.css
I, [2014-12-24T14:03:31.182356 #50624]  INFO -- : Writing ~/ember-cli-rails/public/assets/frontend/vendor-fbc6a340dcc7f1ba6f6c8644788e709b.js

But if you try to precompile in the production environment (which I assume you'd have to to minify the assets) you get only this:

$ rake assets:precompile RAILS_ENV=production
I, [2014-12-24T14:04:34.346453 #50748]  INFO -- : Writing ~/ember-cli-rails/public/assets/application-03f914f41a5b3ea5ccb6944c8b0dfd4f.js
I, [2014-12-24T14:04:34.368663 #50748]  INFO -- : Writing ~/ember-cli-rails/public/assets/application-7eadaa6a15e069d84c07540345524b0e.css

Conflicting chdir

I keep getting warning: conflicting chdir during an other chdir block when I run my tests. This is swallowing any test output. It's coming from lib/ember-cli/app.rb:250.

Seems like a race condition? Seems exec(cmd, method: :spawn) is getting called multiple times. This is a little strange as to my knowledge my app server isn't making multiple threads and I only have one client app.

What application server are you all using?

Will report back once I've found the source.

404s for built .js files in development environment

I've set this up using the simplest possible configuration exactly like the readme suggests, but I'm getting 404s for:
/javascripts/app_name/app-name.js
/javascripts/app_name/vendor.js

When I run rake assets:precompile I see what looks like the build files under public/assets/app_name/vendor-xxxxxxxxxxxxxxxxxx.js etc., so it looks like that works (I have no way to test).

Can you give me a better idea of what I should be seeing in development mode? Should the ember build output be displaying anywhere? Where should I be looking for temporary files? Are their certain asset pipeline config settings that break this?

Looking for assets in wrong path with re-written URI

I have a rails app which is accessed like so:

http://my.blah.com/joe_blow

where joe_blow might be any user portal name.

While the user sees the above url in the browser, the following Apache rewrite rule:

  RewriteCond   %{HTTP_HOST}    ^my.
  RewriteCond   %{REQUEST_URI}  !^/[^\./]*\.[^/]*$
  RewriteRule   ^/([^/]*)/?(.*)  /$2?portal_slug=$1 [QSA,PT]

changes the request behind the scenes to:

http://my.blah.com?portal_slug=joe_blow

After dynamically setting a base href in application.html.erb like so:

<% portal_slug = request.portal_slug %>

<!DOCTYPE html>
<html>
<head>
  <base href=<%= "/#{portal_slug + '/' if portal_slug}" %>>
</head>

the rails app finds its assets with no issues. For example:

/joe_blow/assets/application.js

However, this is not the case using using Ember-CLI and your gem. For whatever reason, it's trying to find the Ember-CLI app's assets under something like

/joe_blow/javascripts/frontend.js

(which I assume corresponds to rails_app/app/assets/javascripts/frontend.js)

instead of something like:

/joe_blow/assets/frontend.js

(which would correspond to rails_app/app/frontend/tmp/...

If I pre-compile (build) the Ember-CLI assets, this issue still remains, as it always looks for the assets in that weird location.

Can you suggest an approach to getting your gem to work with my rails app?

Build failure after changes to app files

 ember-cli: 0.1.12
 node: 0.10.35
 npm: 2.1.8
 ember-cli-rails: 0.1.4

I've got a very simple app that breaks every time I change anything in any file within the ember app directory (i.e., models, templates, config, etc.) The backtrace on the build error says:

  no such file or directory '/Users/.../app/portfolio/tmp/config_loader-tmp_cache_dir-Zjm4zZxY.tmp' at symlink (/Users/.../app/portfolio/node_modules/ember-cli/node_modules/symlink-or-copy/index.js:63:26)

App works fine with ember server on port 127.0.0.1:4200.

Edit: It occurred to me after posting this that the issue might be related to pow server. Indeed, the issue is gone when switching to WEBrick or Thin. Closing this...

Best practices for passing data from Rails to Ember app?

Not sure if this is the appropriate place to ask, but using ember-cli-rails, how might one pass data directly from a Rails controller into the Ember app? Previously, with the ember-rails gem, one could, for example, add a script tag to their layout that modified the globally-accessible App namespace:

<script type="text/javascript">
  App.set('apiKey', '<%= @api_key %>');
</script>

It was also possible to add a .erb extension to JS files and then directly add variables from Rails:

# /app/assets/javascripts/my-app/models/task.js.erb
...
App.Task.reopenClass({
  MAX_NAME_LENGTH: <%= Task::MAX_NAME_LENGTH %>,
  MAX_DETAILS_LENGTH: <%= Task::MAX_DETAILS_LENGTH %>
});

I always thought that these types of "bridges" between your Rails and Ember apps made a compelling case for using ember-rails and serving an Ember app from a layout file as opposed to making the Ember app a separate collection of static files that you can just put on S3. Are there ways to accomplish something similar with ember-cli-rails given Ember CLI's use of modules?

Start apps lazily.

If I have multiple ember-cli apps mounted at various routes (I am working on an app with 6), starting them all for each rails s can take quite a bit of time.

If each ember app takes 3-5 seconds to build, and I have 10 apps running it will take 30-50 seconds to boot rails server (we do a sync build AND an async watch for all apps on boot). This is regardless of hitting any of the ember routes (meaning, if I just want to hit a standard rails route I have to wait the total time).

Dissecting this a bit:

  • Do not compile && run the EmberCLI app. Only one should be needed, it seems that a sync build is required to ensure content exists in dist/. I believe that the locking middleware in #25 fixes this for us. Fixed in #25.
  • Only start apps when their routes are visited. Removes the need for SKIP_EMBER environment variable.

DISCLAIMER:

I could be missing something obvious that makes these points untrue.

trouble getting started: package.json

I'm hitting an error on the package_json method of app.rb.

Just to make sure I've set it up correct, if I have

EmberCLI.configure do |c|
  c.app :frontend, path: '/'
end

in my initializer, I should move my entire existing Ember CLI app to /app/frontend, correct? Does package.json need to be in the root folder or something?

images and other assets

where should we put assets? I have an image in my ember cli app's public folder, but it's not showing up in the rails app.

Little bug with latest ember-cli-version

Hi,

First a big thanks for this project.

After installing this gem and following instructions I've found a little bug

ember-cli version just installed is version: 0.2.0-beta.1

And it seem you check for version 0.1.5 so it break startup of the app with a explicit error message here

Is it possible to bump the required version.

I actually added an initializer in my app which re-open EmberCLI::App to change the version but it seem a little bit ugly.

Tell me if you want more details or if I can help with that

Conditionally suppress Ember, Ember-Data and Handlebars from vendor.js

Similar to this issue, it would be nice to be able to prevent Ember, Ember-Data and Handlebars from being included in vendor.js if the ember-rails gem is present. This would be useful for sites that have more than one ember app. Currently, under this scenario, Ember, Ember-Data and Handlebars are downloaded once for each app.

Really, depending on the presence of the gems to detect jQuery and Ember doesn't cover all use cases. Many teams like to use Bower to include these in their Rails apps (I mean using Bower directly in Rails, not in Ember CLI). Since there's no way to detect that, maybe it would be useful to have additional options in the ember-cli-rails initializer that can manually suppress these imports?

I don't know enough about Ember CLI to know if it will build without Ember included though.

I'm willing to work on this if you think it's a good idea, but it will be a few weeks before I have the time. Thanks for the awesome gem!

Watch command called incorrectly

In ember-cli-rails/lib/ember-cli/app.rb

The watch argument needs 1 passing to it to make it work properly. Also it would be great to be able to configure what watcher is used (--watcher) as developing with this inside a VM using vagrant won't work with default watchers and the polling watcher is needed.

def command(options={})
     watch = options[:watch] ? "--watch" : ""
     "#{ember_path} build #{watch} --environment #{environment} --output-path #{dist_path} #{log_pipe}"
end

Headless test driver performance

The application I'm working on drives the ember application with capybara-webkit, and in some cases, selenium.

I've noticed that the same tests run dramatically slower when using capybara-webkit instead of selenium. For example, the selenium run takes 14 seconds, whereas the same test run with capybara-webkit takes 1 minute and 24 seconds. Aside from being headless vs not headless, I'm not sure what differences might cause this.

I realize this isn't the most helpful "issue" report as I haven't yet identified the problem. Currently looking into the ember-cli-rails internals for something that could be causing this. The gem README mentions "frameworks like cucumber" -- out of curiosity, what test drivers have you tried? Have you noticed anything similar to this report? If so, are there any good debug hooks I can use to get some visibility into what's happening during the build? (e.g maybe it's kicking off builds or getting stuck)

Appreciate any insight, and I'll post any extra information I find.

JRuby support

Hey there, I get Ruby ~> 2.0 needed. Is there a reason not to support JRuby?

Cheers for this!

Export or sync rails models into ember cli apps

Hi,

Thanks for the awesome gem.

I have wondered, could there be a generator that could sync rails models into ember-cli apps, with the corresponding type ?

Something like having a user model in rails ( email, username, password) , with the generator, it would create the rails json serializer ( with email,username, password) and the ember cli model ( also with email, username password ).

Bonus points for the other way around, and specifiyng to more than one ember cli app and keeping them in sync.

What do you guys think ? I would make the "double mvc" overhead much easier to manage.

Ember-cli-rails compiles wrong asset files

I've spent hours figuring out why my "rake assets:precompile" suddenly started failing :)

/lib/ember-cli/app.rb:142 seems to be the root cause:

Rails.configuration.assets.precompile << /(?:\/|\A)#{name}\//

This adds all folders with the same name as the app to the precompile list. I happened to have a css folder with the same name as an ember-cli app. This caused a compilation error because the css files in that folder depend on sass variables defined elsewhere (which are normally imported upfront when compiling the usual application.css file).

Can we change the line in question so that it only adds the specific ember-cli asset folders?

Detect broken build state

Sometimes EmberCLI fails to build assets due to syntax error. Rails does not provide any sort of feedback and continues to serve an old pre-fail version of assets. All that results in the situation where developer refreshes the page several times not realizing that the changes he just made are not included into the resulting assets.

It'd be nice to make EmberCLI::Rails gem to have an ability to detect this state and display an error view similar to the one you see when Assets Pipeline fails to build an asset.

Is there a way to do that without parsing EmberCLI build process output? Maybe there could be a hidden file containing last build error, so we could check for its existence to detect a broken build state?

//cc @rwjblue

Assertion Failed: Path does not start with the provided rootURL

When runing tests via ember-cli-rails combined with a rootURL and baseURL set in the environment and router, it results in the following error:

Error: Assertion Failed: Path /tests/inspiration does not start with the provided rootURL /ig/

environment baseURL: '/ig/'
router rootURL: '/ig/'
tests mounted at '/tests/', application name: 'inspiration'

Setting config.use_ember_middleware = false does not disable middleware in non-production environments

Following the instructions, I do

#test.rb
 config.use_ember_middleware = false

yet the middleware is still loaded. Here's the boolean logic responsible

#ember-cli-rails/lib/ember-cli/helpers.rb, line 28 
def use_middleware?
   rails_config_for(:use_ember_middleware) || non_production?  
end

My intuitive understanding is it should be something like

def use_middleware?
   if(rails_config_defined?(:use_ember_middleware))
      rails_config_for(:use_ember_middleware)
  else
      non_production?
  end
end

Which one is the intended behavior?

Unicorn in development with multiple workers does not work

If you run Unicorn with more than 1 worker in development mode it works only on first load.

Modifying source code of the ember-cli app causes ENOTEMPTY exception, probably because there are more than 1 ember serve processes trying to rebuild the project under the same directory.
Lockfile seems to be ignored.

`frontend/Gemfile not found`

I'm trying to upgrade my version of ember-cli to 0.1.8 (from pre 0.1.6).

It seems like 652cf12 is problematic

Also worth mentioning, ember-cli:install-dependencies and ember-cli:test seem to be running twice.

The failure message:

/Users/Sean/.rbenv/versions/2.2.0/bin/ruby -I/Users/Sean/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/lib:/Users/Sean/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-support-3.1.2/lib /Users/Sean/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
/Users/Sean/src/my-app/frontend/Gemfile not found
/Users/Sean/.rbenv/versions/2.2.0/bin/ruby -I/Users/Sean/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/lib:/Users/Sean/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-support-3.1.2/lib /Users/Sean/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb failed

The full output:

2.2.0 in my-app/ on sd-bump-ember-cli-rails 
› rk

> [email protected] postinstall /Users/Sean/src/my-app/frontend
> bower install


> [email protected] postinstall /Users/Sean/src/my-app/frontend
> bower install

version: 0.1.15
Building..Warning: ignoring input sourcemap for bower_components/route-recognizer/dist/route-recognizer.js because ENOENT, no such file or directory '/Users/Sean/src/my-app/frontend/tmp/tree_merger-tmp_dest_dir-ameG9KTZ.tmp/bower_components/route-recognizer/dist/route-recognizer.js.map'
Built project successfully. Stored in "/Users/Sean/src/my-app/frontend/tmp/class-tests_dist-dHI2i7tJ.tmp".
ok 1 PhantomJS 1.9 - transforms the credit card information for Stripe
ok 2 PhantomJS 1.9 - transforms expiry information when filled in with 1Password
ok 3 PhantomJS 1.9 - FooterNavComponent: it renders
ok 4 PhantomJS 1.9 - InputListComponent: splits value list into strings
ok 5 PhantomJS 1.9 - InputListComponent: splits whitespace separated value list into strings
ok 6 PhantomJS 1.9 - InputListComponent: joins value list to string
ok 7 PhantomJS 1.9 - InputListComponent: joins empty value list to empty string
ok 8 PhantomJS 1.9 - CsvExport: #isFinished returns true when #status is 'finished'
ok 9 PhantomJS 1.9 - User cannot update unchanged form: Update Form butotn is disabled by default, and is enabled when inputs change
ok 10 PhantomJS 1.9 - User changes their email address: shows an error for invalid emails
ok 11 PhantomJS 1.9 - User changes their email address: shows email errors returned from the server
ok 12 PhantomJS 1.9 - User changes their email address: shows password errors returned from the server
ok 13 PhantomJS 1.9 - User changes payment amount: creates a subscription
ok 14 PhantomJS 1.9 - User changes payment amount: they see the correct new total
ok 15 PhantomJS 1.9 - User changes payment amount: they see the new amount for this form in the receipt section
ok 16 PhantomJS 1.9 - User changes payment amount: they see the correct current total
ok 17 PhantomJS 1.9 - User changes payment amount: the slider displays the correct amount
ok 18 PhantomJS 1.9 - User changes payment amount and tries to leave the page: the slider resets to the default when they return
ok 19 PhantomJS 1.9 - User changes payment amount and tries to leave the page: they see a confirmation box and cancel
ok 20 PhantomJS 1.9 - User changes payment amount and tries to leave the page: they see a confirmation box and click ok
ok 21 PhantomJS 1.9 - User creates a form: reenables the create button after submitting
ok 22 PhantomJS 1.9 - User deletes a submission: they are redirected to the previous submission
ok 23 PhantomJS 1.9 - User deletes a submission it is the first (ordered) submission: they are redirected to the next submission
ok 24 PhantomJS 1.9 - User deletes a submission there are no more submissions: they are redirected to the form setup
ok 25 PhantomJS 1.9 - User deletes a submission confirm is false: does not delete the submission
ok 26 PhantomJS 1.9 - User deletes form: and does not see deletion dialog on another form
ok 27 PhantomJS 1.9 - User downloads form as CSV: polling until the export is no longer pending
ok 28 PhantomJS 1.9 - User edits a form: changing the notification emails
ok 29 PhantomJS 1.9 - User edits a form and tries to leave the page: the data is reset when they return
ok 30 PhantomJS 1.9 - User edits a form and tries to leave the page: they see a confirmation box and cancel
ok 31 PhantomJS 1.9 - User edits a form and tries to leave the page: they see a confirmation box and click ok
ok 32 PhantomJS 1.9 - User filters submissions: they see only the filtered submissions
ok 33 PhantomJS 1.9 - User filters submissions: they see help text when all submissions are filtered out
ok 34 PhantomJS 1.9 - User filters submissions when they change forms: the filter is cleared
ok 35 PhantomJS 1.9 - User filters submissions when they filter for spam: the filter is cleared
ok 36 PhantomJS 1.9 - User marks a submission as spam: redirects to the next submission
ok 37 PhantomJS 1.9 - User marks a submission as ham: toggles the spam state
ok 38 PhantomJS 1.9 - User pays for first form: creates their payment account and creates a subscription
ok 39 PhantomJS 1.9 - User transitions to another form: redirects to the most recent submission
ok 40 PhantomJS 1.9 - User transitions to another form the other form has no submissions: when they transition back to the original form, it redirects to the most recent submission
ok 41 PhantomJS 1.9 - User deletes a submission: they are redirected to the previous submission
ok 42 PhantomJS 1.9 - User views a form in sandbox: they see the sandbox warning
ok 43 PhantomJS 1.9 - User views a form with no spam: they do not see the toggle spam link
ok 44 PhantomJS 1.9 - User views a form with no submissions: they see the form setup page
ok 45 PhantomJS 1.9 - User views a form with only spam: they stay on the submission index page
ok 46 PhantomJS 1.9 - User views a form with spam: they do not see the spam initially
ok 47 PhantomJS 1.9 - User views a form with spam: they can toggle to see the spam
ok 48 PhantomJS 1.9 - User views a form with submissions: redirects to the most recent submission
ok 49 PhantomJS 1.9 - User views a form with submissions: they see the submission count
ok 50 PhantomJS 1.9 - User views a form with submissions: the submissions are sorted by date
ok 51 PhantomJS 1.9 - User visits a form that doesn't exist: displays a 404 page
ok 52 PhantomJS 1.9 - User views an unread submission when vist and leave the edit the form: does not trigger a confirm dialog
ok 53 PhantomJS 1.9 - User views dashboard: they see their email
ok 54 PhantomJS 1.9 - User views dashboard they have no forms: they are redirected to the new form page
ok 55 PhantomJS 1.9 - User views dashboard they have a form but have not visited any: they are redirected to the first form
ok 56 PhantomJS 1.9 - User views dashboard they have a visited another form: they are redirected to the form they last visited
ok 57 PhantomJS 1.9 - User views form data tab: the links are to the correct endpoints
ok 58 PhantomJS 1.9 - User toggles spam: redirects to the first submission if there is one
ok 59 PhantomJS 1.9 - User toggles spam: redirects to the submission index if there are no submissions
ok 60 PhantomJS 1.9 - User views the form setup page the form has submissions: they do not see the buttons to advance
ok 61 PhantomJS 1.9 - User views the form setup page the form has submissions: when they click the form they see the submissions
ok 62 PhantomJS 1.9 - User views the form setup page the form has no submissions: they see the buttons to advance to the next section
ok 63 PhantomJS 1.9 - User views the form setup page the form has no submissions: when they click the form they stay on the setup page
ok 64 PhantomJS 1.9 - User views the new form page they have no forms: they see a welcome message
ok 65 PhantomJS 1.9 - User views the new form page they have at least one form: they do not see a welcome message

1..65
# tests 65
# pass  65
# fail  0

# ok
version: 0.1.15
Building..Warning: ignoring input sourcemap for bower_components/route-recognizer/dist/route-recognizer.js because ENOENT, no such file or directory '/Users/Sean/src/my-app/frontend/tmp/tree_merger-tmp_dest_dir-5M4PQPCa.tmp/bower_components/route-recognizer/dist/route-recognizer.js.map'
Built project successfully. Stored in "/Users/Sean/src/my-app/frontend/tmp/class-tests_dist-4MKKy7fP.tmp".
ok 1 PhantomJS 1.9 - transforms the credit card information for Stripe
ok 2 PhantomJS 1.9 - transforms expiry information when filled in with 1Password
ok 3 PhantomJS 1.9 - FooterNavComponent: it renders
ok 4 PhantomJS 1.9 - InputListComponent: splits value list into strings
ok 5 PhantomJS 1.9 - InputListComponent: splits whitespace separated value list into strings
ok 6 PhantomJS 1.9 - InputListComponent: joins value list to string
ok 7 PhantomJS 1.9 - InputListComponent: joins empty value list to empty string
ok 8 PhantomJS 1.9 - CsvExport: #isFinished returns true when #status is 'finished'
ok 9 PhantomJS 1.9 - User cannot update unchanged form: Update Form butotn is disabled by default, and is enabled when inputs change
ok 10 PhantomJS 1.9 - User changes their email address: shows an error for invalid emails
ok 11 PhantomJS 1.9 - User changes their email address: shows email errors returned from the server
ok 12 PhantomJS 1.9 - User changes their email address: shows password errors returned from the server
ok 13 PhantomJS 1.9 - User changes payment amount: creates a subscription
ok 14 PhantomJS 1.9 - User changes payment amount: they see the correct new total
ok 15 PhantomJS 1.9 - User changes payment amount: they see the new amount for this form in the receipt section
ok 16 PhantomJS 1.9 - User changes payment amount: they see the correct current total
ok 17 PhantomJS 1.9 - User changes payment amount: the slider displays the correct amount
ok 18 PhantomJS 1.9 - User changes payment amount and tries to leave the page: the slider resets to the default when they return
ok 19 PhantomJS 1.9 - User changes payment amount and tries to leave the page: they see a confirmation box and cancel
ok 20 PhantomJS 1.9 - User changes payment amount and tries to leave the page: they see a confirmation box and click ok
ok 21 PhantomJS 1.9 - User creates a form: reenables the create button after submitting
ok 22 PhantomJS 1.9 - User deletes a submission: they are redirected to the previous submission
ok 23 PhantomJS 1.9 - User deletes a submission it is the first (ordered) submission: they are redirected to the next submission
ok 24 PhantomJS 1.9 - User deletes a submission there are no more submissions: they are redirected to the form setup
ok 25 PhantomJS 1.9 - User deletes a submission confirm is false: does not delete the submission
ok 26 PhantomJS 1.9 - User deletes form: and does not see deletion dialog on another form
ok 27 PhantomJS 1.9 - User downloads form as CSV: polling until the export is no longer pending
ok 28 PhantomJS 1.9 - User edits a form: changing the notification emails
ok 29 PhantomJS 1.9 - User edits a form and tries to leave the page: the data is reset when they return
ok 30 PhantomJS 1.9 - User edits a form and tries to leave the page: they see a confirmation box and cancel
ok 31 PhantomJS 1.9 - User edits a form and tries to leave the page: they see a confirmation box and click ok
ok 32 PhantomJS 1.9 - User filters submissions: they see only the filtered submissions
ok 33 PhantomJS 1.9 - User filters submissions: they see help text when all submissions are filtered out
ok 34 PhantomJS 1.9 - User filters submissions when they change forms: the filter is cleared
ok 35 PhantomJS 1.9 - User filters submissions when they filter for spam: the filter is cleared
ok 36 PhantomJS 1.9 - User marks a submission as spam: redirects to the next submission
ok 37 PhantomJS 1.9 - User marks a submission as ham: toggles the spam state
ok 38 PhantomJS 1.9 - User pays for first form: creates their payment account and creates a subscription
ok 39 PhantomJS 1.9 - User transitions to another form: redirects to the most recent submission
ok 40 PhantomJS 1.9 - User transitions to another form the other form has no submissions: when they transition back to the original form, it redirects to the most recent submission
ok 41 PhantomJS 1.9 - User deletes a submission: they are redirected to the previous submission
ok 42 PhantomJS 1.9 - User views a form in sandbox: they see the sandbox warning
ok 43 PhantomJS 1.9 - User views a form with no spam: they do not see the toggle spam link
ok 44 PhantomJS 1.9 - User views a form with no submissions: they see the form setup page
ok 45 PhantomJS 1.9 - User views a form with only spam: they stay on the submission index page
ok 46 PhantomJS 1.9 - User views a form with spam: they do not see the spam initially
ok 47 PhantomJS 1.9 - User views a form with spam: they can toggle to see the spam
ok 48 PhantomJS 1.9 - User views a form with submissions: redirects to the most recent submission
ok 49 PhantomJS 1.9 - User views a form with submissions: they see the submission count
ok 50 PhantomJS 1.9 - User views a form with submissions: the submissions are sorted by date
ok 51 PhantomJS 1.9 - User visits a form that doesn't exist: displays a 404 page
ok 52 PhantomJS 1.9 - User views an unread submission when vist and leave the edit the form: does not trigger a confirm dialog
ok 53 PhantomJS 1.9 - User views dashboard: they see their email
ok 54 PhantomJS 1.9 - User views dashboard they have no forms: they are redirected to the new form page
ok 55 PhantomJS 1.9 - User views dashboard they have a form but have not visited any: they are redirected to the first form
ok 56 PhantomJS 1.9 - User views dashboard they have a visited another form: they are redirected to the form they last visited
ok 57 PhantomJS 1.9 - User views form data tab: the links are to the correct endpoints
ok 58 PhantomJS 1.9 - User toggles spam: redirects to the first submission if there is one
ok 59 PhantomJS 1.9 - User toggles spam: redirects to the submission index if there are no submissions
ok 60 PhantomJS 1.9 - User views the form setup page the form has submissions: they do not see the buttons to advance
ok 61 PhantomJS 1.9 - User views the form setup page the form has submissions: when they click the form they see the submissions
ok 62 PhantomJS 1.9 - User views the form setup page the form has no submissions: they see the buttons to advance to the next section
ok 63 PhantomJS 1.9 - User views the form setup page the form has no submissions: when they click the form they stay on the setup page
ok 64 PhantomJS 1.9 - User views the new form page they have no forms: they see a welcome message
ok 65 PhantomJS 1.9 - User views the new form page they have at least one form: they do not see a welcome message

1..65
# tests 65
# pass  65
# fail  0

# ok
/Users/Sean/.rbenv/versions/2.2.0/bin/ruby -I/Users/Sean/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/lib:/Users/Sean/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-support-3.1.2/lib /Users/Sean/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
/Users/Sean/src/my-app/frontend/Gemfile not found
/Users/Sean/.rbenv/versions/2.2.0/bin/ruby -I/Users/Sean/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/lib:/Users/Sean/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-support-3.1.2/lib /Users/Sean/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-3.1.7/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb failed

Rakefile:

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

MyApp::Application.load_tasks

task(:default).clear
task default: ["ember", :spec]
task "ember" => ["ember-cli:compile", "ember-cli:test"]

frontend/package.json:

{
  "name": "frontend",
  "version": "0.0.0",
  "description": "Small description for frontend goes here",
  "private": true,
  "directories": {
    "doc": "doc",
    "test": "tests"
  },
  "scripts": {
    "start": "ember server",
    "build": "ember build",
    "test": "ember test",
    "postinstall": "node_modules/.bin/bower install"
  },
  "repository": "",
  "engines": {
    "node": ">= 0.10.0"
  },
  "author": "",
  "license": "MIT",
  "devDependencies": {
    "bower": "*",
    "broccoli-asset-rev": "^2.0.0",
    "ember-cli": "0.1.15",
    "ember-cli-6to5": "0.2.1",
    "ember-cli-coffees6": "^0.1.3",
    "ember-cli-content-security-policy": "0.3.0",
    "ember-cli-dependency-checker": "0.0.7",
    "ember-cli-google-analytics": "1.2.0",
    "ember-cli-htmlbars": "^0.7.0",
    "ember-cli-ic-ajax": "0.1.1",
    "ember-cli-inject-live-reload": "^1.3.0",
    "ember-cli-jquery-ui": "0.0.13",
    "ember-cli-pretender": "0.3.1",
    "ember-cli-qunit": "0.1.2",
    "ember-cli-rails-addon": "0.0.11",
    "ember-cli-zero-clipboard": "1.0.2",
    "ember-data": "1.0.0-beta.12",
    "ember-export-application-global": "^1.0.0",
    "ember-moment": "^1.0.0",
    "express": "^4.8.5",
    "glob": "^4.0.5"
  }
}

Check for tee support

Currently build server assumes that tee is available. This may not be the case on some OS versions.

We should check for its availability (and whether the terminal is a tty) before adding it to the build command.

ember-cli-rails does not work with ember 1.9

I made an ember-cli-rails app, and it automatically installed ember 1.8.1. It is a very simple app, and you can see the repository here. It runs quite well.

However, when I tried to upgrade to ember 1.9, it stopped working. These are the changes I made.

The following error ActionController::RoutingError (No route matches [GET] "/javascripts/frontend/vendor.js"): started to alternate with this big block of text:

============================= WARNING! =============================

  Seems like Ember frontend application takes more than 5
  seconds to compile.

  To prevent race conditions consider adjusting build timeout
  configuration in your ember initializer:

    EmberCLI.configure do |config|
      config.build_timeout = 10 # in seconds
    end

  Alternatively, you can set build timeout per application like this:

    EmberCLI.configure do |config|
      config.app :frontend, build_timeout: 10
    end

============================= WARNING! =============================

My page never loaded.

Is there a known solution for this? If not, I'm willing to start looking. Any pointers on where to dig would be appreciated.

Ember app in default path degrades perf of Rails

When Ember app is placed in Rails /app folder (i.e. default ember-cli-rails path), perf of Rails (rendering pages, serving assets, etc) degrades significantly due to large number of additional files (bower_components, node_modules) in Rails autoload path.

Quick profiling led to the following method call:
Rack/ActionDispatch::Reloader/call

  • < 1ms without EmberCLI app
  • ~ 150ms with EmberCLI app

As a workaround, EmberCLI app can be just placed to any non-autoload path.

To avoid perf. problems I suggest the following:

  • default app EmberCLI app path should be changed to something outside Rails app folder, e.g. Rails.root.join('jsapp', <appname>)
  • Possible perf. problems when placing EmberCLI app in app folder should be mentioned in the readme.

I have only verified this issue on my local dev machine:
Rails 4.1.7
Ruby 2.2
OS X 10.9.5

deployment using capistrano

wondering if anyone has deployed an ember-cli-rails app using capistrano?

What should happen on the production server after deploy to ensure that the ember part of an ember-cli-rails app works?

I noticed that there are a couple of rake tasks (ember-cli:install_dependencies and ember-cli:compile). Should running both of those after deploy be sufficient ?

  • thanks :-)

Deploying to Heroku fails

Rails: 4.0.2

Package.json:

{
  "name": "new-admin",
  "version": "0.0.1",
  "description": "snip",
  "private": true,
  "directories": {
    "doc": "doc",
    "test": "tests"
  },
  "scripts": {
    "start": "ember server",
    "build": "ember build",
    "postinstall": "../../node_modules/bower/bin/bower install",
    "test": "ember test"
  },
  "repository": "",
  "engines": {
    "node": ">= 0.10.0"
  },
  "author": "",
  "license": "MIT",
  "devDependencies": {
    "broccoli-asset-rev": "^2.0.0",
    "broccoli-coffee": "^0.4.0",
    "broccoli-ember-hbs-template-compiler": "^1.6.1",
    "broccoli-sass": "git://github.com/spiceworks/broccoli-sass",
    "ember-cli": "0.1.11",
    "ember-cli-6to5": "^3.0.0",
    "ember-cli-app-version": "0.3.0",
    "ember-cli-coffeescript": "0.8.0",
    "ember-cli-content-security-policy": "0.3.0",
    "ember-cli-dependency-checker": "0.0.7",
    "ember-cli-ic-ajax": "0.1.1",
    "ember-cli-inject-live-reload": "^1.3.0",
    "ember-cli-jquery-ui": "0.0.13",
    "ember-cli-qunit": "0.3.0",
    "ember-cli-rails-addon": "0.0.11",
    "ember-cli-uglify": "1.0.1",
    "ember-data": "1.0.0-beta.12",
    "ember-export-application-global": "^1.0.0",
    "express": "^4.8.5",
    "glob": "^4.0.5"
  }
}

Everything works locally during development, but deploying to Heroku fails with:

rake aborted!
       NoMethodError: undefined method `directory?' for nil:NilClass
       /tmp/build_3b713c089beab5cd5652456593dc27bb/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:307:in `block in each_entry'
       /tmp/build_3b713c089beab5cd5652456593dc27bb/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:303:in `each'
       /tmp/build_3b713c089beab5cd5652456593dc27bb/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:303:in `each_entry'
       /tmp/build_3b713c089beab5cd5652456593dc27bb/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:322:in `block in each_file'
       /tmp/build_3b713c089beab5cd5652456593dc27bb/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:321:in `each'
       /tmp/build_3b713c089beab5cd5652456593dc27bb/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:321:in `each_file'
       /tmp/build_3b713c089beab5cd5652456593dc27bb/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:335:in `each_logical_path'
       /tmp/build_3b713c089beab5cd5652456593dc27bb/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:115:in `each'
       /tmp/build_3b713c089beab5cd5652456593dc27bb/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:115:in `to_a'
       /tmp/build_3b713c089beab5cd5652456593dc27bb/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:115:in `compile'
       /tmp/build_3b713c089beab5cd5652456593dc27bb/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:60:in `block (3 levels) in define'
       /tmp/build_3b713c089beab5cd5652456593dc27bb/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/rake/sprocketstask.rb:146:in `with_logger'
       /tmp/build_3b713c089beab5cd5652456593dc27bb/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:59:in `block (2 levels) in define'
       Tasks: TOP => assets:precompile
       (See full trace by running task with --trace)
 !
 !     Precompiling assets failed.
 !

 !     Push rejected, failed to compile Multipack app

I am building the Ember applications styles from the ember-cli styles directory using SASS.

Any ideas?

Issue with puma concurrency

When developing get the error:

16:16:33  file changed styles/main.less
16:16:33  file changed styles/main.less
16:16:36  EEXIST, file already exists '/Users/{user}/data/{project}/tmp/ember-cli-477a1ffb-8359-4e3f-a1ec-86741c388c36/apps/dashboard/assets/vendor.map'

Workaround:

Found that reducing the max concurrent workers to 1 fixed the issue.

An error running rails server

/Users/lairdd/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/ember-cli-rails-0.0.2/lib/ember-cli-rails.rb:21:in prepare!': private methodprepend' called for Rack::Server:Class (NoMethodError)

rails: 4.1.4
ruby: 2.0.0p353

Am I doing something wrong? Is it related to rbenv

Cheers
Dave

Static assets in an Ember project get asset hashed and made unreachable in production

Create an ember project and include bootstrap. Create a test page with some glyphicons.

Deploy to production.

Glyphicons cannot be loaded, because Rails has gone ahead and asset hashed everything thus changing the filename that the Bootstrap CSS (that was compiled in your Ember app before it reaches rails) and now the filename used is incorrect.

Perhaps more of an FYI?

Not working properly with Zeus

Hello mister mantainer :)

There is a problem with Zeus. Apparently, a signal 2 (https://github.com/rwz/ember-cli-rails/blob/master/lib/ember-cli/app.rb#L41) doesn't kill the ember child processes created while running within a server created by zeus s (zeus server).

This is a huge problem because when i press ctrl+c in a terminal running zeus s the rails process dies but not the child processes created. The screen seems to hangout and if i just close the terminal, the processes keep living and if i run zeus s again, more processes are created draining my battery and causing undesirable race conditions in the ember build process (i debugged one for a while before discovering that there was many embers running).

The proper solution would be to kill all the child process of the main ember process (to skip having some orphans). I already did this in my machine:

exec("pkill -TERM -P #{pid}")

But i don't know if there is no other way to accomplish this. Do you think is a good solution to the problem? I know is a specific problem of people using Zeus so i'm asking what you think before making a PR.

PD: Sorry for my english.

Can't compile Sass in production mode and can't debug it

I can run my app in development mode just fine, and I can run rake assets:precompile fine, but if I run RAILS_ENV=production rake assets:precompile I get this:

Sass::SyntaxError: Invalid CSS after "": expected selector or at-rule, was "{}"
(in /Users/Glenn/Sites/ajam/ajam-mobile-middleware/tmp/ember-cli-576f8aa5-74f7-4d4c-9db7-56e96c0a41f8/assets/mm-ember/mm-ember.css.map)

"mm-ember" is the name of my ember-cli project folder. At this point, the file it references does not exist so I can't look into it. I don't know how to get more verbose output and I don't know how to disable source maps to see if that helps.

Any ideas for me?

Errors and Exceptions should not be silently piped to an unreachable log file on Heroku

In app.rb the output from executing the Ember-CLI build is silently piped to a log file:

https://github.com/rwz/ember-cli-rails/blob/master/lib/ember-cli/app.rb#L18

This is bad on Heroku, because it looks like the build succeeds and causes a downstream exception to be raised in Sprockets because the files it was told to expect don't exist because of the build failure. In general this is a bad thing™ to do. It is also a violation of the 12factor application principles with regard to logging:

It should not attempt to write to or manage logfiles. Instead, each running process writes its event stream, unbuffered, to stdout. During local development, the developer will view this stream in the foreground of their terminal to observe the app’s behaviour.

There are two ways I see to addressing this:

  1. Check for a specific EMBER_CLI_RAILS_VERBOSE environment variable that disables suppression of STDOUT.
  2. Check for existence of BUILDPACK_URL environment variable to indicate we are running on Heroku and shouldn't suppress STDOUT.

Happy to make PRs with the relevant changes if open to them.

Suppressing gems

Please please make it possible to NOT suppress the use of jQuery-rails gem given the following scenario:

  • Use ember-cli-rails
  • Use ember-cli
  • User rails-admin (which requires jQuery-rails)

So a boolean to prevent this would be perfect in the config files. As it is now we need to override the suppress function.

Make sure ember-cli-dependency-checker is present

Without it there could be a situation when one developer runs npm install --save-dev ember-cli-rails-addon and commits changes to package.json, but then other developer pulls the change and runs rails without running npm install.

NPM doesn't actually perform any dependency checking before executing the code, so builds are running without the addon, and all sorts of weird shit happening. :(

deploying to heroku: ember-cli executable not found

Any thoughts on this? Is it possible to have the server install ember-cli via ember-cli-rails?

remote:        ember-cli executable could not be found
remote:        /tmp/build_c29c20414fc576c1008f3b4d2b04e5f9/vendor/bundle/ruby/2.0.0/gems/ember-cli-rails-0.0.10/lib/ember-cli/configuration.rb:22:in `block in ember_path'
remote:        /tmp/build_c29c20414fc576c1008f3b4d2b04e5f9/vendor/bundle/ruby/2.0.0/gems/ember-cli-rails-0.0.10/lib/ember-cli/configuration.rb:21:in `tap'
remote:        /tmp/build_c29c20414fc576c1008f3b4d2b04e5f9/vendor/bundle/ruby/2.0.0/gems/ember-cli-rails-0.0.10/lib/ember-cli/configuration.rb:21:in `ember_path'
remote:        /tmp/build_c29c20414fc576c1008f3b4d2b04e5f9/vendor/bundle/ruby/2.0.0/gems/ember-cli-rails-0.0.10/lib/ember-cli/app.rb:72:in `ember_path'
remote:        /tmp/build_c29c20414fc576c1008f3b4d2b04e5f9/vendor/bundle/ruby/2.0.0/gems/ember-cli-rails-0.0.10/lib/ember-cli/app.rb:137:in `command'
remote:        /tmp/build_c29c20414fc576c1008f3b4d2b04e5f9/vendor/bundle/ruby/2.0.0/gems/ember-cli-rails-0.0.10/lib/ember-cli/app.rb:17:in `block in compile'
remote:        /tmp/build_c29c20414fc576c1008f3b4d2b04e5f9/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/core_ext/kernel/reporting.rb:54:in `silence_stream'
remote:        /tmp/build_c29c20414fc576c1008f3b4d2b04e5f9/vendor/bundle/ruby/2.0.0/gems/ember-cli-rails-0.0.10/lib/ember-cli/app.rb:16:in `compile'
remote:        /tmp/build_c29c20414fc576c1008f3b4d2b04e5f9/vendor/bundle/ruby/2.0.0/gems/ember-cli-rails-0.0.10/lib/ember-cli-rails.rb:66:in `block in each_app'
remote:        /tmp/build_c29c20414fc576c1008f3b4d2b04e5f9/vendor/bundle/ruby/2.0.0/gems/ember-cli-rails-0.0.10/lib/ember-cli-rails.rb:66:in `each'
remote:        /tmp/build_c29c20414fc576c1008f3b4d2b04e5f9/vendor/bundle/ruby/2.0.0/gems/ember-cli-rails-0.0.10/lib/ember-cli-rails.rb:66:in `each_app'
remote:        /tmp/build_c29c20414fc576c1008f3b4d2b04e5f9/vendor/bundle/ruby/2.0.0/gems/ember-cli-rails-0.0.10/lib/ember-cli-rails.rb:40:in `compile!'
remote:        /tmp/build_c29c20414fc576c1008f3b4d2b04e5f9/vendor/bundle/ruby/2.0.0/gems/ember-cli-rails-0.0.10/lib/ember-cli/helpers.rb:26:in `block (2 levels) in override_assets_precompile_task!'

Documentation: Where to create a new ember app in a Rails app

@rwz Where do you suggest a newbie (in this case, me) can create an ember app (with ember-cli) for a Rails project?

That info would be useful for newbies, and could perfectly fit inside the project's README file.

As soon as I get an answer I can send you a PR with an updated README :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.