Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 93745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:23:33+00:00 2026-05-10T23:23:33+00:00

I have some settings I need in a Javascript file — servers to connect

  • 0

I have some settings I need in a Javascript file — servers to connect to — that changes based on my environment. For development, test, and staging, I want to use the staging servers; for production, the production servers. I already have the settings in Ruby (configured in my environment/xyz.rb files). So far, I’ve been dynamically creating the JS files at request time with an application.js.erb file and a custom route. This is pretty slow, though, and it means creating an extra controller and views directory just for this file.

I would prefer to have a template file and a rake task that generates the correct version from the template and places a static file in the public/javascripts directory. Has anyone tried something like this? What did you use for rendering? Where did you put the template file and the rendering code?

Or is it better to just keep the dynamic version and cache it in production?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:23:34+00:00Added an answer on May 10, 2026 at 11:23 pm

    Can you do something like this?

    <% javascript_include_file '#{RAILS_ENV}.js' %> 

    I do something similar, though it is not with a JS file, but with some RB files … and I do it for the same reason, determining which servers to connect to.

    For me, I have an rb file in my 'lib' directory called 'constants.rb'. This file has a few if statements that switch based on environment (development, test, staging, or production) that switch out the values of the ip addresses that I need to attach to. It is peppy enough for my purposes on the behemoth of a machine that I have the application running on.

    Here is a sample:

    if ENV['RAILS_ENV'] != 'production' ## if the rails environment is development or staging then use the test server   @@IP_ADDRESS = '10.16.121.173' ## the test server else ## if the Rails environment is production, then use the live server.   @@IP_ADDRESS = '10.16.8.44' ## The is the shared IP address end 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your event handlers form a closure that remember a "live"… May 11, 2026 at 11:54 pm
  • Editorial Team
    Editorial Team added an answer I would have both. I would keep the files renamed… May 11, 2026 at 11:54 pm
  • Editorial Team
    Editorial Team added an answer You haven't posted any code related to $nodes so I… May 11, 2026 at 11:54 pm

Related Questions

I have some settings I need in a Javascript file -- servers to connect
I have an app that is run from a compiled DLL on a web
I have a javascript function that manipulates the DOM when it is called (adds
this may seem trivial but I'm setting up, on a profile form page I'm
I have a function defined in AS3 that's gonna be called from client side

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.