Redmine Plugin - requires restart after every code change - ruby-on-rails

I am working on some plugin on redmine (project management web application written using Ruby on Rail).
For every change i make to the code of the plugin(say view.html.erb file), i have to restart the redmine(application) server. This is because, it runs on production mode by default.
Will running the application on development mode, solve this problem?
If yes, how can i change its running mode or over-ride this behavior so that classes are loaded per every request (yes this will not be efficient but will be good for development) and changes to the code reflect without restarting the application application server(redmine in this case)
I tried adding this line to environment.rb file
ENV['RAILS_ENV'] ||= 'development'
Also tried answers/comments posted below, but they did'nt solve my problem.
Any working solution would be of great help.
Thank You.
Other Related information:
It uses Rails 2.3.14
and its installed using bitnami stack

For automatic plugin reload on Rails 2.3:
Add config.reload_plugins = true on config/environment.rb. It has to be there, you can't put it on config/environments/development.rb due to the Rails start up steps. You may add if RAILS_ENV = 'development' instead.
config/environment.rb
config.reload_plugins = true
On the plugin's init.rb, add the following line:
init.rb
ActiveSupport::Dependencies.explicitly_unloadable_constants = 'YourPluginModuleName'
That's all. Don't forget to remove it when you're done.

Related

Bitnami Redmine - Development Process

I would like to install Redmine using the Bitnami stack. I have to build custom NEW pages in Redmine and perform some reporting - hence play around with some ROR code.
Can you please suggest me a good development process, as I will have to stop and restart Redmine's service upon every change.
Should I not use Bitnami for development (develop with a thin server first) and at the end merge/replace my files in Bitnami's Redmine folder?
You could switch to rails development environment. In this mode source code files are read by server upon every request.
Change database.yml, so it will have the same configuration options as in production mode. It is better to create separate database for development environment, but not necessary, since you're already developing in production.
Find your web-server configuration file and change in there environment to development.
There is other simpler way. Since (for now) you are interested only in source code updates per request, you can change only one parameter in rails configuration to do so. Open config/environments/production.rb and change line
config.cache_classes = true
to
config.cache_classes = false
Usually this option set to false in development with the following comment:
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.

Rails 3: how to detect if the application is running in server mode for multiple different environment?

I have an app that runs on multiple servers:
- locally on dev machines
- on heroku
- on a specific server with Passanger on Nginx
I am trying to launch a particular code (loading some REDIS keys) that is only required if the web server is launched.
I have done quite a bit of digging, and the nicest solution I found was to execute my code in an initializer with:
if defined?(Rails::Server)
#my code
end
This works well locally, but it seems that Rails::Server never gets defined either on Heroku or Passanger.
I need a solution that works in every case, please help, this is really important.
Thanks,
Alex
ps: I am running Rails 3.0.4, Ruby 1.8.7
Putting code in your config.ru file might be a more robust way of detecting server mode across different types of servers (Unicorn/Passenger/Rails::Server/etc).
e.g., in rails-root/config.ru:
# This file is used by Rack-based servers to start the application.
# ADD this line and read the value later:
ENV['server_mode'] = '1'
require ::File.expand_path...
What about?
config.serve_static_assets = ( defined?(Mongrel) || defined?(WEBrick) ) ? true : false

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.

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.

How do I force Capistrano deployed app to use my development database?

I have a app that I'm deploying to a development server using Capistrano. I'd like to force this deployment to use the development database. So far the only way I've managed to do it is to make my production database info in database.yml equal to the development info. But this is a complete hack.
I've tried setting rails_env to development in deploy.rb but that hasn't worked.
Thoughts?
I ended up using the solution over here. Basically a recipe to replace a line in environment.rb after deploy but before restart.
The problems seems to be with DreamHost's Passenger config. It assumes you're running in production mode.
I'd use Capistrano Ext in order to define multiple deployment environments. I have used this in the past to deply staging and production installations of my apps, so I think it'd work well for you.
Jamis Buck has a writeup if you'd like an overview on how to use it.

Resources