Arc*_*Arc 5 ruby routing ruby-on-rails single-table-inheritance ruby-on-rails-3
我已经为person类实现了单表继承
class Person < ActiveRecord::Base
end
class Teacher < Person
end
class Student < Person
end
class Outsider < Person
end
Run Code Online (Sandbox Code Playgroud)
而创建人似乎根据form.select中选择的内容创建了Teacher,Student或Person,并添加了type属性.
但是,我似乎打破了路线
<%= link_to'Edit',edit_person_path(@deal)%> | <%= link_to'Back',persons_path%>
它们似乎指向teacher_path,student_path和outsider_path而不是person_path.
路线需要做哪些改变?
首先为您的模型生成控制器...
rails generate controller Persons
rails generate controller Teachers
rails generate controller Students
rails generate controller Outsiders
Run Code Online (Sandbox Code Playgroud)
然后在routes.rb中(rails 3)
resources :persons
resources :teachers
resources :students
resources :outsiders
Run Code Online (Sandbox Code Playgroud)
为您提供 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"}
Run Code Online (Sandbox Code Playgroud)
老师、学生、外人都一样
检查耙路或耙路 | grep 教师
| 归档时间: |
|
| 查看次数: |
1045 次 |
| 最近记录: |