Switch between environments

Hi All,

It is my understanding that there are 3 environments built-in to Rails
(Test, Development[default], Production).

Can someone please explain exactly how you switch between them
(specially between Development and Production)?

Let’s say I use the default Sqlite3 database for both Development and
Production; what are the exact steps to push out the completed site so
it’s viewable via Apache web server (instead of WEBrick)

Please excuse my ignorance but it seems rather difficult to find a
concise answer to this question anywhere.

Thank You Very Much.

~Kal

First of all, thank you Hassan.

Why “bundle execute”? What does that do?

I don’t mean database instance. I mean a scenario where I’m using
Sqlite3 application for both Development and Production.

By “push out”, I mean after you’ve finished the application
development (which can be viewed using port 3000), how do we then
“migrate” the finished production into production?

I most likely have multiple concepts confused but I certainly do
appreciate you taking the time to clarify.

Thank Again,

~Kal

On Apr 18, 12:48am, Hassan S. [email protected]

On Tue, Apr 17, 2012 at 8:02 PM, Kal [email protected] wrote:

It is my understanding that there are 3 environments built-in to Rails
(Test, Development[default], Production).

Can someone please explain exactly how you switch between them
(specially between Development and Production)?

bundle exec rails s # starts development
RAILS_ENV=production bundle exec rails s # starts production

(simplistically - varies depending on web server/platform)

Let’s say I use the default Sqlite3 database for both Development and
Production;

You almost certainly don’t want to use the same DB instance for both.

                what are the exact steps to push out the completed site so

it’s viewable via Apache web server (instead of WEBrick)

What do you mean by “push out”? Where are you doing your
coding and testing, and where do you intend to run production?

And the choice of web server has nothing to do with the question
of development/test/production mode.

Please excuse my ignorance but it seems rather difficult to find a
concise answer to this question anywhere.

Maybe because you’re conflating multiple activities/concepts.


Hassan S. ------------------------ [email protected]
http://about.me/hassanschroeder
twitter: @hassan

/* sorry for the near-empty response - fat-fingered it */

On Tue, Apr 17, 2012 at 10:05 PM, Kal [email protected] wrote:

Why “bundle execute”? What does that do?

bundle exec runs your app with the gems specifically described in
your Gemfile.

I don’t mean database instance. I mean a scenario where I’m using
Sqlite3 application for both Development and Production.

Probably still not a great idea unless the production instance will
be very lightly loaded.

By “push out”, I mean after you’ve finished the application
development (which can be viewed using port 3000), how do we then
“migrate” the finished production into production?

What exactly do you mean by “production”? Is this an Intranet app
for your company, an application for a wide Internet public, or ____?

If it’s a public app, you need to decide on hosting; there’s a range of
options, from having your own server in a datacenter to using a cloud
provider like AWS or Heroku. If it’s company-internal, you still need a
server, but the options may be more limited :slight_smile:

That’s a decision that’s only slightly related to Rails, though.


Hassan S. ------------------------ [email protected]
http://about.me/hassanschroeder
twitter: @hassan

On Tue, Apr 17, 2012 at 10:05 PM, Kal [email protected] wrote:

Why “bundle execute”? What does that do?

`bundle exec

Thank Again,

(specially between Development and Production)?

concise answer to this question anywhere.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Hassan S. ------------------------ [email protected]
http://about.me/hassanschroeder
twitter: @hassan

Send me your profile.
Thank you.

18.04.2012 10:59, Kal написал:

http://stackoverflow.com/questions/7291381/rails-how-to-migrate-data-from-development-sqlite3-database-to-production-mysql…this
may be helpful to migrate from development to production.

Thanks Hassan,

This is exactly what I don’t get!

The “Development” environment is the default environment in Rails,
yes?

Now, that means my data is contained in development.sqlite3 and ‘rails
server’ starts WEBrick and so we can view the site from
www.homepage.com:3000.

The step after this is precisely what I’m missing… because nobody
talks about it… all the books and guides pretty much stop short of
this…

So this is my question: How do I move everything to the “production
environment”. I’d imagine that is the ultimate goal, is it not?

How do I copy the data to production.sqlite3 (just issue: rake
db:migrate RAILS_ENV=production) and have all the code (which I
created in the Development Env) working in the “Production”
environment so it doesn’t have to be served out using WEBRick.

Thanks Much,

~Kal

It’s just a test app. However, my plan is to deploy a web application
on a public website… someday :slight_smile:

By the way, I’m running:

Ruby 1.9.3p0
Rails 3.1.3
Phusion Passenger version 3.0.11
CentOS release 5.6
Server version: Apache/2.2.3


On Apr 18, 2:42am, Hassan S. [email protected]

ok…I browsed across some gems and found this:
https://github.com/mattconnolly/rails-backup-migrate …this helps in
dumping the whole database in a single file which can then be restored.
Let
me know if it works in your case

On Apr 18, 2012, at 4:23 AM, Kal wrote:

Thanks Much Aash,

But as someone already replied:

“It only creates tables, but how to transfer data from these tables?
And I think It is same that rake db:migrate RAILS_ENV=production”

I’ve gotten as far as “rake db:migrate RAILS_ENV=production” from my
research thus far…

The whole idea behind separate databases and separate /data/ is that you
want your development environment to run quickly and lightly (on your
local computer) and you may want to entirely drop the database at some
point to try out a different approach. Then you migrate the changes made
during development to the production server (a separate physical machine
or cloud appliance).

The database on your production server should have nothing to do with
the database you hack on in development. (It is good practice to use the
same type of database in both places, but even that is not entirely
required. I have often made simple sites with squilte3 in development
and MySQL in production.) Any production content should only be entered
into the production server’s database.

If you make changes to the dev server, you do so using migrations, and
when you next synch the server with your latest changes, you shell into
the server and run

RAILS_ENV=production bundle exec rake db:migrate

to /alter/ the database with existing data intact.

Seriously, there’s no official document for a “Standard” way of doing
this?

The standard way of doing this is to have development and test run on
the development computer (usually a Mac or *nix desktop or laptop) and
to have production run on a real server somewhere (usually Apache/Nginx

  • Passenger on a *nix server). More elaborate or server-coupled sites
    may have a staging or test environment on a duplicate *nix server, but
    that depends a lot on your application.

I recommend that you read through the entire Rails Tutorial by Michael
Hartl. It’s free to read online, and there’s a paid version with
screencasts that’s also very nice. This will walk you through the
standard way of working in Rails, starting with tests and development on
your local computer, culminating with hosting the site on Heroku. Really
start at the beginning and work your way all the way to the end. I think
you’re missing a few steps here in your understanding.

Walter

On Tue, Apr 17, 2012 at 11:59 PM, Kal [email protected] wrote:

So this is my question: How do I move everything to the “production
environment”. I’d imagine that is the ultimate goal, is it not?

Actually, no.

How do I copy the data to production.sqlite3

To amplify on other responses, it’s not at all typical to share data
between dev and prod databases. There are sometimes tables of
common data: search on ‘Rails seed data’ for more info, or look at
the result of bundle exec rake -T | grep seed .

But if you want to load all the data from your dev instance to your
production system, that’s not a Rails function, and how to best do
it really depends on your particular databases and requirements.

HTH,

Hassan S. ------------------------ [email protected]
http://about.me/hassanschroeder
twitter: @hassan

Thanks Much Aash,

But as someone already replied:

“It only creates tables, but how to transfer data from these tables?
And I think It is same that rake db:migrate RAILS_ENV=production”

I’ve gotten as far as “rake db:migrate RAILS_ENV=production” from my
research thus far…

Seriously, there’s no official document for a “Standard” way of doing
this?

Cheers,

~Kal

Thank you very much Walter, not only for this very concise answer
(which explains a lot), but for all of your help with my previous
inquiries.

Yes, I was very much under the impression that development and
production is meant to be (or at least, can be) performed on the same
physical machine running Rails.

I’ve been working off of Agile Web D. with Rails (4th
Edition). On your recommendation, I picked up Michael H.'s book
today.

I also think this book will help fill in the gaps of information in
this rat maze of my brain.

Thanks Much,

~Kal

Thank you very much, Hassan. Your answer definitely helps a lot.

I’m obviously framing the ROR environments concept incorrectly.

It looks like I’ve got to hit the books a lot harder to avoid straying
down the wrong path.

Thanks,

~Kal

On Apr 18, 12:35pm, Hassan S. [email protected]