Using STI path with same controller

Posted by TenJack on Stack Overflow See other posts from Stack Overflow or by TenJack
Published on 2010-03-16T20:16:11Z Indexed on 2010/03/16 20:41 UTC
Read the original article Hit count: 278

I am using STI and am wondering, do I have to have a separate controller for each model? I have a situation where I only use the create and edit actions for one model in the STI relationship, but I get an 'undefined method' error if I try to do a form for. More specifically, I have two models that inherit from List:

class RegularList < List
class OtherList < List

and I have a lists controller that handles these actions, but I only create new models with RegularList using forms. i.e. the only situation where I use a form_for to create a new List object is with RegularList. What I would like to do is something like:

class ListsController < ApplicationController

def new
  @list = RegularList.new
end

otherwise the route for creating a new list looks like regular_list/new but I would like it to just be list/new. Thoughts?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about single-table-inheritance