0

Hey in my rails app i want to store wether and app is on a Production environment or Development. In my activerecord migration i set the field for :environment ad an integer, 0 is development and 1 is production. Then when i want to use this as plain text i have a helper method that converts this to text from the 0 and 1. Should i store this value in my database as an integer or plain text? I would like to use the most efficient way be cause i would like to make a method like if twitter.is_development() do this.

2 Answers 2

1

It would make more sense to store it as an integer because they represent numbers. If you wanted to use text then "true" and "false" would be more suitable.

Whatever you decide you won't be able to measure the difference in performance. Choose what is easiest to understand and maintain. "Premature optimization is the root of all evil".

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you i cannot agree more with Premature optimization is the root of all evil. I find myself spending pointless time trying to fix whats not broken.
1

I would name the column as "env" and use "production", "development" and "testing" as values to indicate the current env.

You cant predict the future and storing the raw value helps you in many places, like lets say, I call a rake task like,

"rake product:update_price RAILS_ENV=production",

then I would use the value retrieved from the env column without any logic, like

"rake product:update_price RAILS_ENV=#{env}",

so that if its development, production or testing it will use accordingly.

Check this, Rails.env vs RAILS_ENV, maybe you dont need to store anything at all.

1 Comment

The use of the environment isn't for my rails app but for a service im building for other users. Thanks for the answer tho.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.