BIG RAILS - The train is coming...

11/06/2010 — Single Table Inheritance in Ruby on Rails 0 comments [Feed]

Categories: Routing, Ruby On Rails, Design Patterns

I'm developing an application and i had to implement STI. Not because i wanted but because i had the following pattern:

Dealing with network hosts. I had src and dst address. Both are, in the end, network objects

So i created a class named NetworkObject. And i did a STI like

class Src < NetworkObject end

and

class Dst < NetworkObject end

I added a new type to my NetworkObject class type string via migration and i had to generate the restful controllers for both classes. As i use the nifty_scaffold(http://github.com/ryanb/nifty-generators) (from ryan Bates), i just asked to generate both controllers, skipping the models and it added automatically the map.resources to my routes.rb. After that, i was able to manage all components.

Go back to the index

Comments

Add Comment

(required)
(required, won't be displayed)

(Use Markdown syntax)