Ruby on Rails - basic example in ruby on rails - ruby on rails tutorial - rails guides - rails tutorial - ruby rails
Example
Step1:First we need a table to hold our data
Sep2:Then lets create some models
- When you do a Guest.create(name: 'Bob') ActiveRecord will translate this to create an entry in the Users table with type: 'Guest'.
- When we retrieve the record bob = User.where(name: 'Bob').first the object returned will be an instance of Guest, which can be forcibly treated as a User with bob.becomes(User)
- "becomes" is most useful when dealing with shared partials or routes/controllers of the superclass instead of the subclass.