
ruby on rails logo
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: 
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:

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: 19% [?]


Latest Comments