views:

678

answers:

4

I am trying to learn a bit of Ruby. I've installed Ruby on my Ubuntu machine and I am using apache. Everything works fine except to refresh a view I have to restart apache in the console and then hit ctrl-r, just pressing ctrl-r won't refresh the browser.

Apparently there's some caching going on, but does it have to be that way i.e. is it inherent to Ruby on Rails? I tried googling on this but it seems the only answer is to install some long-winded routine. For developing it seems like quite the tedious way to go.

A: 

Apache is not a good choice for development in cases like Rails, because you will indeed need to restart the server every time you change code. Rails ships with its own development server that you can start by executing (IIRC) script/server. It's much more suitable for development, as it needn't be restarted after every little change.

Nick Lewis
I agree that you shouldn't use apache for dev, mongrel is much easier, but setting the RailsEnv in passenger to development means that it doesn't do all the caching of views, classes etc, so you shouldn't have to restart. Still think it's just easier to use mongrel or webrick for local dev though
brad
i disagree. it has been my experience that keeping the development environment as close to the deployment environment saves a lot of trouble when going live, especially with respect to additional modules and third party libraries. We faced issues when we used Debian during development and then had to deploy on CentOS with SELinux enabled... keep development environment as close to deployment environment.
kinjal
+3  A: 

Don't use apache for development mode. Use script/server and install the mongrel gem (sudo gem install mongrel). Mongrel is faster than WEBrick and dumps the development log to the console in which it runs. It makes development decent.

Ben Hughes
Except in Vista. Mongrel is slow as can be in Vista, use webrick instead.
Tilendor
Ruby/Rails is just slow in general on Windows. It's honestly easier to develop in a Linux VM, especially if your app is sufficiently non-trivial. I'm pretty sure that my current project doesn't even run on non-*nix systems.
Ben Hughes
A: 

I'm using Apache with Passenger (aka modrails) for development purposes, and it works fine here. Just make sure to use Rails in development mode by setting "RailsEnv development" in your httpd.conf.

dhofstet
+1  A: 

Apache's a perfectly good choice for development.

Just install Passenger (mod_rails)...and follow the instructions...

I set it up for each site so that /etc/hosts contains

127.0.0.1 myapp

I use Apache virtual hosts with an entry like so - in /etc/apache2/sites-available/myapp

<VirtualHost *:80>
  ServerName myapp
  DocumentRoot /path/to/myapp/public
  RailsEnv development
  RailsAllowModRewrite off
    <directory "/path/to/myapp/public">
      Order allow,deny
      Allow from all
    </directory>
</VirtualHost>

Enable and restart

sudo a2ensite myapp
sudo /etc/init.d/apache2 restart

That way, there's no running script/server ... it's just always running in dev mode - just point your browser to http://myapp

mylescarrick
Just what I wanted. I tried the Mongrel solution above with Apache as a front-end but this is a much nicer solution when you already have all this apache-stuff configured for your php-development and just want to get up and running.
Reed Richards