Rails server does not take in account the production and still used development db

0 down vote favorite

Hi, since several days I have this problem:

For a few days it has worked and now I can't do it works again. I setup
a rails server on ubuntu with apache-2. I used a git repository to get
all new change. After I run
sudo rake db:migrate RAILS_ENV=production

But after have restart apache server I can see that rails use the
development db and not the production while before it has used it.

MORE INFO:
   While I'm trying to understand the problem I note something: When I
execute rake db:migrate RAILS_ENV=production I can see that it create me
the production db. But if I add new value in db I can see it still used
development. I'm continuing my search on google :D. But if someone knows
the answer

I don't really understand what can cause this. So i really appreciate
some help.

Gregory Grimaux wrote in post #965148:

0 down vote favorite

Hi, since several days I have this problem:

For a few days it has worked and now I can't do it works again. I setup
a rails server on ubuntu with apache-2. I used a git repository to get
all new change. After I run
sudo rake db:migrate RAILS_ENV=production

You shouldn't be using sudo for that.

But after have restart apache server I can see that rails use the
development db and not the production while before it has used it.

Then you have not set your RAILS_ENV environment variable correctly.
You can usually do that in the Apache config file.

I assume you're using Passenger (and if not, you should). If I remember
correctly, there is info in the Passenger docs on how to do this.

MORE INFO:
   While I'm trying to understand the problem I note something: When I
execute rake db:migrate RAILS_ENV=production I can see that it create me
the production db.

Right, because RAILS_ENV=production puts you in the production
environment -- for that task only.

But if I add new value in db I can see it still used
development. I'm continuing my search on google :D. But if someone knows
the answer

I don't really understand what can cause this. So i really appreciate
some help.

Simple: as I explained above, environment variables are not being set
correctly. When you specify an environment variable on the command
line, it is only used for that command.

Please gain a better understanding of how environment variable work in
*nix.

Best,

Marnen Laibow-Koser wrote in post #965154:

Gregory Grimaux wrote in post #965148:

0 down vote favorite

Hi, since several days I have this problem:

For a few days it has worked and now I can't do it works again. I setup
a rails server on ubuntu with apache-2. I used a git repository to get
all new change. After I run
sudo rake db:migrate RAILS_ENV=production

You shouldn't be using sudo for that.

OK I will not used sudo in future.

But after have restart apache server I can see that rails use the
development db and not the production while before it has used it.

Then you have not set your RAILS_ENV environment variable correctly.
You can usually do that in the Apache config file.

I assume you're using Passenger (and if not, you should). If I remember
correctly, there is info in the Passenger docs on how to do this.

I'm using passenger with apache2. In my sites I set
RailsEnv production

So I think it should be OK.

MORE INFO:
   While I'm trying to understand the problem I note something: When I
execute rake db:migrate RAILS_ENV=production I can see that it create me
the production db.

Right, because RAILS_ENV=production puts you in the production
environment -- for that task only.

But if I add new value in db I can see it still used
development. I'm continuing my search on google :D. But if someone knows
the answer

I don't really understand what can cause this. So i really appreciate
some help.

Simple: as I explained above, environment variables are not being set
correctly. When you specify an environment variable on the command
line, it is only used for that command.

Please gain a better understanding of how environment variable work in
*nix.

I'm sorry I don't understand what you mean by *nix maybe you're talking
about nginx

I'm sorry I don't understand what you mean by *nix maybe you're talking
about nginx

He is talking about UNIX dude

Vladimir Rybas wrote in post #965318:

I'm sorry I don't understand what you mean by *nix maybe you're talking
about nginx

He is talking about UNIX dude

OK :smiley: Sorry. I found my error. I had two site configured in my apache
configuration. One with rails= prod and one with rails = dev. And of
course it was using rails = dev. So I think I found my problem. I will
let a message to confirm. I need to made some fix on server now since it
does not start correctly.

Gregory Grimaux wrote in post #965320:

Vladimir Rybas wrote in post #965318:

I'm sorry I don't understand what you mean by *nix maybe you're talking
about nginx

He is talking about UNIX dude

OK :smiley: Sorry. I found my error. I had two site configured in my apache
configuration. One with rails= prod and one with rails = dev. And of
course it was using rails = dev. So I think I found my problem. I will
let a message to confirm. I need to made some fix on server now since it
does not start correctly.

Now I have a another problem. It works in my development environment but
no in production.

*** Exception ArgumentError in
PhusionPassenger::Railz::ApplicationSpawner (No association found for
name `machines'. Has it been defined yet?) (process 16052):
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/nested_attributes.rb:245:in
`accepts_nested_attributes_for'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/nested_attributes.rb:222:in
`each'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/nested_attributes.rb:222:in
`accepts_nested_attributes_for'
from /home/et1/wip3/sophia/app/models/machines_operatingsystem.rb:2

But I don't understand why.

Gregory Grimaux wrote in post #965329:

Gregory Grimaux wrote in post #965320:

Vladimir Rybas wrote in post #965318:

I'm sorry I don't understand what you mean by *nix maybe you're talking
about nginx

He is talking about UNIX dude

OK :smiley: Sorry. I found my error. I had two site configured in my apache
configuration. One with rails= prod and one with rails = dev. And of
course it was using rails = dev. So I think I found my problem. I will
let a message to confirm. I need to made some fix on server now since it
does not start correctly.

Now I have a another problem. It works in my development environment but
no in production.

*** Exception ArgumentError in
PhusionPassenger::Railz::ApplicationSpawner (No association found for
name `machines'. Has it been defined yet?) (process 16052):
from

/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/nested_attributes.rb:245:in

`accepts_nested_attributes_for'
from

/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/nested_attributes.rb:222:in

`each'
from

/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/nested_attributes.rb:222:in

`accepts_nested_attributes_for'
from /home/et1/wip3/sophia/app/models/machines_operatingsystem.rb:2

But I don't understand why.

Error found my fault.