views:

41

answers:

1

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?

EDIT: The problem is when I use the above code, I get an 'undefined method' error. My view looks like this: <% form_for(@list) do |f| %> ... <% end %>

So it seems that there is some problem with using a RegularList object in the Lists controller and this is the main problem I am trying to address. Sorry, I realize that was not the clearest explanation.

A: 

I am using STI and am wondering, do I have to have a separate controller for each model?

No, you don't.

klew