I have an app I'm building to learn rails. It's a simple page manager that uses awesome_nested_set to create nested pages. I would like to use STI but am unsure on how to make that work. Most of the examples I see of STI involve a main "Pets" model and sub models of "Dog" and "Cat"; I'm having a hard time making that into a real world example. Here's how I am using the pages.
3 different page "types": Blog, Photo, Mobile Photos. Only way to really describe this is to show you my current site built in Coldfusion Blog, Photo, Mobile Photos.
All use the same table and pretty much the same attributes. The photo sections use a photo attribute and have some minor changes such as uploading, resizing, etc -- but other than that everything is the same between the different "types". The main difference between the page types is how the page will be laid out and how they are accessed. For example:
On the index:
/photos - layout thumbnails to show all pages w/ a type of "Photo"
/blog - layout to show all pages w/ a type of "Blog"
On the show:
/photos/1 - show large photo w/ prev/next photo
/blog/2 - show blog entry w/ prev/next entry
Do I need a separate controller for each type? Do I need separate models if I don't need any changes in the way pages are created/updated? Do I just create routes that point to an action which renders the layout I need? I think I'm seeing the term "STI" and making it more difficult than it has to be. I'm just being cautious because I want to learn the "rails way". Do I even need STI?
Any help would be greatly appreciated, I just need to get over this hump, someone help make it "click"! :)
Here I have written a blog post which will guide you step by step in accomplishing STI.
As far as the Photo class goes where you have to upload images you can do this
class Photo < Page
attr_accessor :photo_file_name, :photo_file_size, :photo_file_type
has_attached_file :photo,
:url => "#{your_upload_url}",
:path => "#{your_upload_path}"
end
If you use this code you must have a column with name photo in you Page model that will store the file_name of the uploaded file.
Hope this helped you. I am here if you need more suggestions on this. :D
UPDATE
After reading the question once again I realised that you also need a separate page for all the child STI classes. Hence you will be needing different controllers to handle that.