How do I use different js to load in production and development environments?

Asked 2 months ago, Updated 2 months ago, 3 views

I am using rails 3.2.

in development mode

in production mode

Is it possible to use ?

I use ajaxzip3 zip code search library.
This is because I use https in the production environment and http in the development environment.

The link above contains the following:It's easy to operate only in the production environment, but it won't be fun if it doesn't work in the development environment (^^;

# For http servers, use
# For https servers, use 

javascript ruby-on-rails

2022-09-30 14:19

2 Answers

The request.protocol and the Helper method will help you write clearly.

module ApplicationHelper
    file_name = ssl ?? 'ajaxzip3-https.js': 'ajaxzip3.js'

  def ssl?

<!DOCTYPE html>
  <title>Your app name</title>
  <%=stylesheet_link_tag 'application', media: 'all'%>



Also, if you want to use it for production, you may need to specify the file in config.assets.precompile.


I hope it will be helpful.

2022-09-30 14:19

app/views How about writing the following in HTML?

<%if Rails.env.production?%>
  <script src=""></script>
  <script src=""></script>

This is what Slim looks like.

-if Rails.env.production?
  script src=""
- else
  script src=""

2022-09-30 14:19

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.