Search code examples
ruby-on-railsactiverecordsti

Rails - Component from Component Library and STI


I have a rails app I'm working on. I've hit a bit of a wall with the database structure. I have Users. These users have Projects, and the projects have components. I want to have the user be able to choose from some existing components then edit the values. I want the components they choose from to come from a database. And I want the resulting component to be a new component. To make life a little more confusing, there are different types of components, I'd like to DRY up these classes into something like

Component < ActiveRecord::Base
  # component stuff
end

SubComponent < Component
  # sub-component stuff
end

Then in 1 controller and 1 view I'd like the user to be able to handle all the components.

Thanks in advance.


Solution

  • Well since this question was kinda vague, I'm going to just post what I've come up with, so if people stumble upon this question there is at least something useful here.

    This is a example app I've made to illustrate some aspects of STI and nested resources together. http://rails-example-association.herokuapp.com

    There is a link to the source on github on the site.