Seals
there were some really nice flowers there
Azuzu posing
The dirt is caused by sides of the cliffs and gouges out rocks and dirt from the sides. This is then pushed to the surface by th
Brandy the White Oceans Resort Dog - she was suppose to show us where to go snorkelling, but we'd had enough for the day.
Cliff
if you forget something at the car, you can always get it!
PC290012.JPG

 

April 2009
M T W T F S S
« Feb   May »
 12345
6789101112
13141516171819
20212223242526
2728293031  

using RoR with apache Alias’

ruby on rails logo

ruby on rails logo

I've been fighting with Ruby on Rails for the past couple of months and I've finally decided that I need to devote more alone time with it. The first big hurdle that I've struck is that when I use Apache and RoR with Aliases, I tend to get the following error when I follow any tutorials/sample code:

Routing Error

No route matches "/tutorial/people" with {:method=>:get}


A quick note about the setup. I'm using RoR with fcgi and apache2 to frontend it. The appropriate apache config setup is (assuming that the code base is /var/rails/Contact) :

    # http://godbit.com/article/beginners-guide-to-rails-part-1
    Alias /tutorial /var/rails/Contact/public
    <directory /var/rails/Contact/public>
        Options ExecCGI FollowSymLinks
        AddHandler cgi-script .cgi
        AllowOverride all
        Order allow,deny
        Allow from all
    </directory>

The next thing that I do is to modify the .htaccess file in the /var/rails/Contact/public/.htaccess to let it know that it's in an aliased location and that I want to use the .fcgi version of the rails.

# General Apache options
#AddHandler fastcgi-script .fcgi
#AddHandler cgi-script .cgi
AddHandler fcgid-script .fcgi
Options +FollowSymLinks +ExecCGI

# If you don't want Rails to look in certain directories,
# use the following rewrite rules so that Apache won't rewrite certain requests
#
# Example:
#  RewriteCond %{REQUEST_URI} ^/notrails.*
#  RewriteRule .* - [L]

# Redirect all requests not available on the filesystem to Rails
# By default the cgi dispatcher is used which is very slow
#
# For better performance replace the dispatcher with the fastcgi one
#
# Example:
#  RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
RewriteEngine On

# If your Rails application is accessed via an Alias directive,
# then you MUST also set the RewriteBase in this htaccess file.
#
# Example:
#  Alias /myrailsapp /path/to/myrailsapp/public
#  RewriteBase /myrailsapp
RewriteBase /tutorial/
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

# In case Rails experiences terminal errors
# Instead of displaying this message you can supply a file here which will be rendered instead
#
# Example:
#  ErrorDocument 500 /500.html

ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"

So far, we've told Apache about the site and if I go to something like http://www.minigeek.org/tutorial (which may or may not work depending on whether I have deleted the content), you'll get a page like this:
ror start page
If you then try to follow the trail down, such as http://www.minigeek.org/tutorial/people as shown by

wernstrom:/var/rails/Contact/public# rake routes
(in /var/rails/Contact)
              people GET    /people                          {:action=>"index", :controller=>"people"}
    formatted_people GET    /people.:format                  {:action=>"index", :controller=>"people"}
                      POST  /people                          {:action=>"create", :controller=>"people"}
                      POST  /people.:format                  {:action=>"create", :controller=>"people"}
          new_person GET    /people/new                      {:action=>"new", :controller=>"people"}
formatted_new_person GET    /people/new.:format              {:action=>"new", :controller=>"people"}
          edit_person GET    /people/:id/edit                {:action=>"edit", :controller=>"people"}
formatted_edit_person GET    /people/:id/edit.:format        {:action=>"edit", :controller=>"people"}
              person GET    /people/:id                      {:action=>"show", :controller=>"people"}
    formatted_person GET    /people/:id.:format              {:action=>"show", :controller=>"people"}
                      PUT    /people/:id                      {:action=>"update", :controller=>"people"}
                      PUT    /people/:id.:format              {:action=>"update", :controller=>"people"}
                      DELETE /people/:id                      {:action=>"destroy", :controller=>"people"}
                      DELETE /people/:id.:format              {:action=>"destroy", :controller=>"people"}
                            /:controller/:action/:id       
                            /:controller/:action/:id.:format

You get a Action Controller error such as:

ror error

I had originally fixed this problem by modifying the routes.rb file, but I went looking for a better solution and I found that Mike had encountered exactly the same problem (which he originally fixed with routes.rb as well), but his more elegant solution is to edit the environment which:

has the added advantage of fixing things like linked stylesheets and stuff as well

So, how do you do it?

wernstrom:/var/rails/Contact# vi config/environment.rb
...
# After
Rails::Initializer.run do |config|
    config.action_controller.relative_url_root = "/tutorial"
...
wernstrom:/var/rails/Contact#

I found that this didn't take effect until I did a restart of apache:

wernstrom:/var/rails/Contact# /etc/init.d/apache2 restart

I hope that this helps.

Popularity: 26% [?]

Everybody's a critic WTF?? Nothing about this made senseas useful as a blindfolded monkey throwing dartsmediocre ... at bestsolved my problem but needed modificationspectacular.  \'Nuff said (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>