Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rails.env to RailsContext #697

Closed
robwise opened this issue Jan 27, 2017 · 6 comments
Closed

Add Rails.env to RailsContext #697

robwise opened this issue Jan 27, 2017 · 6 comments

Comments

@robwise
Copy link
Contributor

robwise commented Jan 27, 2017

Heroku Preboot is a feature on Heroku that allows for faster deploy times. When you promote your staging app to production, Preboot simply switches the production server to point at the staging app's container. This means it can deploy much faster since it doesn't have to rebuild anything.

However, this means that if you use the Define Plugin to provide the rails environment to your client code as a variable, that variable will erroneously still have a value of Staging instead of Production. Providing Rails.env (which is accurate even in Preboot) in the default Rails context would be a nice enhancement.

@justin808
Copy link
Member

@robwise Easy to add, either via a custom Rails Context enhancement (no PR required) or as a default for the RailsContext.

See this example: https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/config/initializers/react_on_rails.rb#L4

module RenderingExtension
  # Return a Hash that contains custom values from the view context that will get passed to
  # all calls to react_component and redux_store for rendering
  def self.custom_context(view_context)
    if view_context.controller.is_a?(ActionMailer::Base)
      {}
    else
      {
        somethingUseful: view_context.session[:something_useful]
      }
    end
  end
end

@robwise
Copy link
Contributor Author

robwise commented Jan 31, 2017

@justin808 yeah I'm already doing it the custom way, I'm saying I think it should be a default

@justin808
Copy link
Member

@robwise Maybe for features, we'll do if any of our Coaching Clients or regular clients want it? Otherwise, we can wait for the PR to come in. Or maybe if the issue gets at least 20 up votes.

@robwise
Copy link
Contributor Author

robwise commented Jan 31, 2017

okay, and maybe just having this issue as a historical record will be good enough in case other people are using preboot and are not realizing that because the webpack isn't being recompiled, the variables may be stale and to watch out for that

@jonathanphilippou
Copy link
Contributor

i'm gonna take it

@justin808
Copy link
Member

Fixed in #1065.

justin808 added a commit that referenced this issue Apr 22, 2018
superdev9082 added a commit to superdev9082/react_on_rails that referenced this issue Feb 16, 2023
Web-Go-To added a commit to Web-Go-To/react-with-rails that referenced this issue Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants