I am new to RoR, but I have been struggling with a mysterious error
for days. I am using a standard installation approach on a clean
ubuntu system
I created a very simple application, just reading from a mysql table
called dogs. The application was totally generated with scaffold.
rails server -p 3001 #Starts server
When I run, I get the error “No route matches controller”
http://localhost:3001/dogs
If I remove all the link_to cells, the application runs and returns
data.
If I put back just one line " <%= link_to ‘Show’, dog %>",
I still get the error complaining about the ":action=>“destroy”
route.
== scaffold ==
rails g scaffold dog dog_id:integer color:string gender:string
dog_name:string --skip-migration
===========Generated Source Code=============
<% @dogs.each do |dog| %>
<%= dog.dog_id %> <%= dog.color %> <%= dog.gender %> <%= dog.dog_name %> <%= link_to 'Show', dog %> <%= link_to 'Edit', edit_dog_path(dog) %> <%= link_to 'Destroy', dog, :confirm => 'Are you sure?', :method => :delete %> <% end %>========= ERROR ===========
No route matches controller
Showing /home/ruby/hub2/app/views/dogs/index.html.erb where line #20
raised:
No route matches {:controller=>“dogs”, :action=>“destroy”, :id=>#<Dog
dog_id: 1, color: “Golden”, gender: “Female”, dog_name: “Daisy”>}
Extracted source (around line #20):
17: <%= dog.color %>
18: <%= dog.gender %>
19: <%= dog.dog_name %>
20: <%= link_to ‘Show’, dog %>
21: <%= link_to ‘Edit’, edit_dog_path(dog) %>
22: <%= link_to ‘Destroy’, dog, :confirm => ‘Are you
sure?’, :method => :delete %>
23:
========== routes.rb ==============
Hub2::Application.routes.draw do
resources :dogs
end
========= rake routes ============
root@ubu-bob:/home/ruby/hub2# rake routes
(in /home/ruby/hub2)
dogs GET /dogs(.:format)
{:controller=>“dogs”, :action=>“index”}
dogs POST /dogs(.:format)
{:controller=>“dogs”, :action=>“create”}
new_dog GET /dogs/new(.:format)
{:controller=>“dogs”, :action=>“new”}
edit_dog GET /dogs/:id/edit(.:format)
{:controller=>“dogs”, :action=>“edit”}
dog GET /dogs/:id(.:format)
{:controller=>“dogs”, :action=>“show”}
dog PUT /dogs/:id(.:format)
{:controller=>“dogs”, :action=>“update”}
dog DELETE /dogs/:id(.:format)
{:controller=>“dogs”, :action=>“destroy”}
=== Installation ===
I followed these instructions on a brand new and fully updated
version of ubuntu 10.04
http://castilho.biz/blog/2010/05/08/how-to-install-ruby-on-rails-on-ubuntu-10-04-lucid-lynx/
How to install Ruby on Rails on Ubuntu 10.04 Lucid Lynx
Follow these steps to have a fresh installation of Ruby on Rails
in Ubuntu 10.04:
sudo su
apt-get -y install build-essential
apt-get -y install ruby rdoc libopenssl-ruby
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
tar zxvf rubygems-1.3.7.tgz
cd rubygems-1.3.7
ruby setup.rb
ln -s /usr/bin/gem1.8 /usr/local/bin/gem
gem install rails ;# (takes awhile with no output… )
#Installing MySQL gem:
apt-get -y install ruby-dev libmysql-ruby libmysqlclient-dev
gem install mysql
======