我使用腳手架啓動了Rails應用程序。該應用將人們與機構聯繫起來。當我去沒有路線匹配控制器顯示 - 腳手架生成的代碼
我收到以下錯誤:
No route matches {:controller=>"people", :action=>"show", :id=>#<Person pid: 302, name:
(等)
如果我刪除了腳手架生成表中的所有「的link_to」細胞,頁面加載就好了。這個錯誤發生在我應用程序中的所有index.html.erb文件中。
這裏是我的人/ index.html.erb
<h1>Listing people</h1>
<table> <tr> <th></th>
<th></th>
<th></th>
<th></th> </tr>
<% @people.each do |person| %> <tr> <td><%= person.name %></td>
<td><%= link_to 'Show', person %></td>
<td><%= link_to 'Edit', edit_person_path(person) %></td>
<td><%= link_to 'Destroy', person, :confirm => 'Are you sure?', :method
=> :delete %></td> </tr> <% end %> </table>
<br />
<%= link_to 'New Person', new_person_path %>
我的控制器/ people.rb
class PeopleController < ApplicationController
# GET /people
# GET /people.xml
def index
@people = Person.all(:order => "year_grad, name")
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @people }
end
end
# GET /people/1
# GET /people/1.xml
def show
@person = Person.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @person }
end
end
的開始和耙路線的結果
people GET /people(.:format) {:controller=>"people", :action=>"index"}
POST /people(.:format) {:controller=>"people", :action=>"create"}
new_person GET /people/new(.:format) {:controller=>"people", :action=>"new"}
edit_person GET /people/:id/edit(.:format) {:controller=>"people", :action=>"edit"}
person GET /people/:id(.:format) {:controller=>"people", :action=>"show"}
PUT /people/:id(.:format) {:controller=>"people", :action=>"update"}
DELETE /people/:id(.:format) {:controller=>"people", :action=>"destroy"}
home_index GET /home/index(.:format) {:controller=>"home", :action=>"index"}
root /(.:format) {:controller=>"home", :action=>"index"}
和人的遷移
class CreatePeople < ActiveRecord::Migration
def self.up
create_table :people, :id => false, :primary_key => :pid do |t|
t.integer :pid, :null =>false
t.string :name
t.string :degree
t.integer :phd_area
t.string :thesis_title
t.integer :year_grad
t.integer :instid_phd
t.integer :year_hired
t.integer :instid_hired
t.integer :schoolid_hired
t.integer :deptid_hired
t.string :email
t.string :notes
t.integer :hire_rankid
t.integer :tenure_track
t.integer :prev_instid
t.integer :prev_rankid
end
end
def self.down
drop_table :people
end
end
這裏是我的routes.rb文件(減去註釋行是腳手架自動生成):
IHiring::Application.routes.draw do
resources :ranks, :departments, :institutions, :schools, :people
get "home/index"
root :to => "home#index"
end
它是否有東西做設置不同的primary_key爲表?我不確定它是模型還是路線問題。或者我沒有想到的東西。腳手架後我重新啓動了我的Rails服務器。
給它一個鏡頭。同樣的錯誤。 :( – Libby 2011-01-30 19:10:44
你可以發佈你的整個的routes.rb文件? – 2011-01-30 19:12:59