Created
June 25, 2012 11:39
-
-
Save Tigraine/2988112 to your computer and use it in GitHub Desktop.
Persons Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@person = Person.first # a Person | |
link_to @person.name, @person # => /persons/1 | |
@student = Student.first # a Student | |
link_to @student.name, @student # => /students/2 | |
# this allows stuff like this: | |
@persons = Person.all # Person.all also includes Students | |
# @persons will look like this: [Person, Student, ..] | |
@persons.each do |p| | |
link_to p.name, p | |
end | |
# => /persons/1, /students/2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddTypeColumnToPersons < ActiveRecord::Migration | |
def change | |
add_column :person, :type, :string | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person < ActiveRecord::Base | |
end | |
class Student < Person | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@persons = Person.all | |
@persons.each do |p| | |
link_to @p.name, edit_polymorphic_path(p) | |
end | |
# => /persons/1/edit, /students/2/edit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@persons = Person.all | |
@persons.each do |p| | |
link_to p.name, edit_person_path(p) | |
# => /persons/1/edit, /persons/2/edit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment