YAML anchors issue - ruby-on-rails

Here is the tutorial I'm following: http://rhnh.net/2011/01/31/yaml-tutorial
I'm using the SettingsLogic gem: https://github.com/binarylogic/settingslogic
And every config file used by Settings logic works fine, but if I use the same tactics on database.yml or thinking_sphinx.yml it will not work.

My bad I didn't specified full stack info.
I'm using passenger. But I missed directive RailsEnv in apache config file.
http://www.modrails.com/documentation/Users%20guide%20Apache.html#rails_env
By default, passenger loads production environment.
Setting RailsEnv staging solved my problem. And now correct settings picked.

Related

Changing the base URL for Rails 3 development

I know I'm going to deploy to an environment with my application running with a base URL which looks like this:
http://someserver/mydepartment/myapp
My development environment is set up to use the default Rails configuration, which looks like this:
http://localhost:3000/myapp
I'd like to model this deployment path in my development environment. That is, I'd like to develop with a base URL which looks like this:
http://localhost:3000/mydepartment/myapp
That way, I can make all my URLs relative to "/" and they will work in both environments.
How can I change it so my application will live at this path in my development environment?
Solutions I've found, but don't work for me:
Setting the scope in routes.rb doesn't seem to work for the static content in public.
Using Apache's rewriting capabilities. I don't want to install Apache on my development box. Ideally the solution would work with WEbrick, though I seem to have Mongrel mostly working as well (there are some problems with Mongrel and Ruby 1.9.2).
Setting relative_url_root and similar suggestions which don't work with Rails 3.
Dynamically generating CSS/JavaScript and adjusting the paths to compensate between development and production environments.
You can try mapping your rails app rack config to a different base_uri.
All you need to do is wrap the existing 'run' command in a map block
try doing this in your rails 'config.ru' file:
map '/mydepartment' do
run Myapp::Application
end
Now when you 'rails server' the app should be at localhost:3000/mydepartment .
Not sure if this will give you the desired outcome, but worth a try.
Here’s how you can deploy a Rails 3.1 app to a subdirectory in Apache, replacing config.action_controller.relative_url_root which no longer exists.
In config/routes.rb:
scope 'my_subdir' do
# all resources and routes go here
end
In your Apache configuration file:
Alias /my_subdir /var/www/my_subdir/public
<Location /my_subdir>
SetEnv RAILS_RELATIVE_URL_ROOT "/my_subdir"
PassengerAppRoot /var/www/my_subdir
</Location>
And it should work, including automatically pointing all your assets to /my_subdir.

Environments in Rails

I have read that deploying an application on development environment may be one of the worst cases, but i couldn't find any real information about HOW i can change the environments of my applications and make their production databases ready?
I am using Passenger/Nginx for deployment by the way.
Edit : People you get it wrong, maybe i asked wrong, i know how to change environments by nginx, but if i change it from nginx and don't touch to my app, it crashes. There are some things i have to done to my app before i change their environment from development to production, i want info about them.
In your virtual host put following environment variable:-
<VirtualHost *:80>
DocumentRoot /var/apache2/htdocs/tutorial/Web/
ServerName dev.tutorial.local
SetEnv FLOW3_CONTEXT Production
</VirtualHost>
http://www.modrails.com/documentation/Users%20guide%20Nginx.html#RailsEnv
From the Passenger documentation, RAILS_ENV defaults to production.
If not you can specify it in the nginx configuration:
In the http configuration block.
In a server configuration block.
In a location configuration block.
In an if configuration scope.
I am not sure. but try changing environment varaible in config/environment.rb
ENV['RAILS_ENV'] ||= 'production'

Ruby on Rails: How to set which development environment an app runs in?

I'm relatively new to Ruby on Rails and occasionally I find this convention-over-configuration stuff a little confusing as a lot of things seemed to be hidden from the developer, as in this case.
I'm using rails 2.3.8 and when I run my app locally through NetBeans 6.9/Mongrel on my system it runs using the development environment parameters.. when I deploy it to a Fedora box and run it there in Apache HTTPD it automatically runs using the production environment parameters.
How does my app know which environment to use? I haven't changed anything in my app to set the environment.. both versions locally and on my Fedora box are identical. I can't find anywhere in the code where it is setting the environment.. so how is this working?
Thanks.
In httpd.conf file, write the following in VirtualHost:-
## Specify Rails Environment here,
default value is "production"
RailsEnv development
Thanks...
The primary way to specify rails mode is RAILS_ENV environment variable (I assume development is default, when nothing is specified). You can check its value in bash, echo $RAILS_ENV.
You can also modify ENV['RAILS_ENV'] in your config file to change the mode:
ENV['RAILS_ENV'] = 'production'
edit
I've never used rails with apache, but I think passenger mod can also specify this variable somewhere, checking apache configs might help.

Rails 3 - set environment

I have a rails 3 app (which I upgraded). It runs on passenger and nginx but on my production server it also starts with the environment set to 'production'. I know I am missing something really basic, but I just can't figure out where to set the environment instead of in environment.rb.
Thanks for helping!
UPDATE: ok, I learned I can still do that with Rails.env = 'production'.
That seems kind of old school to me. Do you know an elegant way to configure this maybe in the Capfile or sth like that?
Rails 3 is a little bit different than Rails 2.x in that it has a config.ru file, like other Rack applications.
Passenger detects rails as a Rack app, so you'll have to use RackEnv instead of RailsEnv in the vhost. You can set the environment using RackEnv as per the documentation for Passenger/Nginx.
You can configure a different RAILS_ENV for each app in your vhost for nginx with passenger. I've never used nginx but in apache it's just a RailsEnv=development directive. That way each site just has it set, no worries with configuring a cap task or variable or anything. See the docs. Note that the default is production so this should already be set for you.

How do I force RAILS_ENV=development from within environment.rb or initializers?

Our host does not allow us to modify the passenger config file (i.e. the apache config OR the vhosts file), but we'd like to run rails in dev mode. So we have to specify the environment (prod/dev/test) in one of the files that rails loads AS the application is restarted. Anyone know how to do this?
We've tried the following with no luck:
#environment.rb (before any other code is executed)
`RAILS_ENV=development` # using back ticks
ENV['RAILS_ENV'] = 'development' # assigning to a constant
RAILS_ENV='development' # as suggested by one of the answers, unfortunately does not work.
Setting it right at the top of environment.rb with:
RAILS_ENV = 'development'
should do it. It's possible that passenger overrides this, though.
If you don't have access to the passenger config but you do have access to your virtual hosts then you can also just force it in there with:
RailsEnv development
Why don't you change your production.rb config to match the settings found in development.rb?
In envriornment.rb you could add:
RAILS_ENV="production"
RAILS_ENV.freeze
That way when it tries to get reset later, it will fail.
I'm not sure what other ramifications this will have later or if it will permeate everywhere within rails.
Instead of setting ENV["RAILS_ENV"] in environment.rb, do so in boot.rb.
See here for details.
RAILS_ENV="production"
RAILS_ENV.freeze/ENV
That way when it tries to get reset later, it will fail.
I'm not sure what other ramifications this will have later or if it will permeate everywhere within rails.

Resources