0

Let's say you have different settings in development vs. production ( different options, different timings for setInterval/setTimeout ). How do you handle changes between configurations?

I was thinking of using a generator, and everytime I switch between environments, I could regenerate the relevant js files. What is your approach?

2 Answers 2

2

Very, very simply. In my layout:

<% if Rails.env.development? %>
  <%= javascript_include_tag "development.js" %>
<% end %>
Sign up to request clarification or add additional context in comments.

2 Comments

Why do I always take the complicated path? ... but still, you'd have to keep 2 versions of the same source file under version control, right?
No, you'd have a development.js file which is conditionally included, and a normal application.js which is always included.
1

Depending on how many of these different settings you have, I would use the ENV['RAILS_ENV'] (Rails 2.3, it might have changed in Rails 3+) to see if you are in 'production', 'development', etc.

If it's just a stylesheet or javascript file I would have these checks in the application layout. If your switches are more in depth, I would make a helper in the application helper which would tell you which environment your're code's currently in and just call that helper from your code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.