tricknotes / ember-cli-rails

Unify your EmberCLI and Rails Workflows
http://thoughtbot.github.io/ember-cli-rails/
MIT License
713 stars 205 forks source link

Documentation for EMBER_ENV RAILS_ENV is confusing (maybe a quick table needed?) #526

Closed uhrohraggy closed 7 years ago

uhrohraggy commented 7 years ago

The current documentation for RAILS_ENV is a bit confusing. Current copy:

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.

Particularly given the example, it says to check for the absence of the RAILS_ENV variable to indicate development mode, and then the last line says it will be absent in production builds, so it leads me to understand mirage would be set to enabled in production, correct?

My particular issue is that we have a Rails Environment named stage - but appears to load the Ember application using production. There of course could be an issue with something in between, but if RAILS_ENV=stage, what gets set as the ember environment? (Is stage non-standard?) - I will use EMBER_ENV but I think a quick table of supported Rails environments and the combinations of EMBER_ENV, RAILS_ENV (development, staging, production, non-standard, etc.) and what they'll be set to after build would be super helpful.


Which operating system and version is the project developed on? Mac OSSierra 10.12.4

Which version of ruby is the project developed on? Ruby 2.3.3

Which version of npm is the project developed on? NPM 4.1.2 Node 7.5.0

Which version of ember-cli is the project developed on? Ember-cli 2.12.1

What is the rails version? Rails 5.0.1

What is the ember-cli-rails version (from Gemfile)? ember-cli-rails (0.8.4) cocaine (~> 0.5.8) ember-cli-rails-assets (~> 0.6.2) html_page (~> 0.1.0) railties (>= 3.2)

What is the ember-cli-rails-addon version (from package.json)? "ember-cli-rails-addon": "^0.7.1",

Is your application server multi-threaded (such as puma and unicorn) or is it multi-process (such as thin and webrick)? puma

What are the contents of config/initializers/ember.rb? EmberCli.configure do |c| c.app :frontend end

What are the contents of the Rails' view that renders the Ember application?

<%= render_ember_app :frontend do |head, body| %>
  <% head.append do %>
    <%= csrf_meta_tags %>
      <link rel="stylesheet" href="/assets/vendor.css">
      <link rel="stylesheet" href="/assets/app2.css">
 ...
  <% body.append do %>
    <div id="rails-generated-content" style="display: none;">
      <%= yield %>
    </div>

    <%= include_ember_script_tags :frontend %>

    <% if content_for?(:custom_includes_js) %>
      <%= yield(:custom_includes_js)%>
    <% else %>
      <%= javascript_include_tag 'admin_ember' %>
    <% end %>
...
  <% end %>
<% end %>

How is the application deployed? Capistrano

nruth commented 7 years ago

Is stage non-standard

Yes it's non-standard so you'll get a production build of ember according to those docs.

it says to check for the absence of the RAILS_ENV variable to indicate development mode, and then the last line says it will be absent in production builds, so it leads me to understand mirage would be set to enabled in production, correct?

No, because the environment isn't 'development' so that code inside the if statement won't run.

It's a nice trick that lets you run your ember app in development both with and without its hosting rails app: without the rails app (localhost:4200) you can run it just with the mirage fake api, or with/through the rails app (localhost:3000) you can turn mirage off and have ember hit the local rails server.

uhrohraggy commented 7 years ago

Thanks @nruth really appreciate the answer, and makes total sense.