实现单表继承后,Rails路由中断 [英] Broken Rails Routes after implementing Single Table Inheritance
问题描述
我已经为人员类实现了单表继承
I have implemented single table inheritance for a person class
class Person < ActiveRecord::Base
end
class Teacher < Person
end
class Student < Person
end
class Outsider < Person
end
创建人似乎正在创建老师,学生或人,具体取决于在form.select中选择的内容,并添加了type属性。
And the create person seems to work creating Teacher, Student or Person according to the what is chosen in the form.select and the type attribute is added.
但是,我似乎打破了路线
However, I seem to have broken the routes
<%= link_to'Edit',edit_person_path(@deal)%> |
<%= link_to'Back',personspath%>
<%= link_to 'Edit', edit_person_path(@deal) %> | <%= link_to 'Back', persons_path %>
它们似乎指向教师路径,学生路径和outsider_path而不是person_path。
They seem to point to teacher_path, student_path and outsider_path instead of person_path.
需要对路线进行哪些更改?
What changes need to be made in the routes?
推荐答案
首先为您的控制器生成控制器模型...
first generate controllers for your models...
rails generate controller Persons
rails generate controller Teachers
rails generate controller Students
rails generate controller Outsiders
然后在route.rb中(rails 3)
then in routes.rb (rails 3)
resources :persons
resources :teachers
resources :students
resources :outsiders
为您提供REST路由
例如
persons GET /persons(.:format) {:action=>"index", :controller=>"persons"}
new_person GET /person/new(.:format) {:action=>"new", :controller=>"persons"}
edit_person GET /persons/:id/edit(.:format) {:action=>"edit", :controller=>"persons"}
person GET /persons/:id(.:format) {:action=>"show", :controller=>"persons"}
persons POST /spersons(.:format) {:action=>"create", :controller=>"persons"}
person PUT /persons/:id(.:format) {:action=>"update", :controller=>"persons"}
person DELETE /persons/:id(.:format) {:action=>"destroy", :controller=>"persons"}
对于老师,学生和局外人都是一样
the same for teacher, student and outsider
检查耙路
或耙路| grep老师
check rake routes or rake routes | grep teachers
这篇关于实现单表继承后,Rails路由中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!