Controller inheritance and nested attributes Error

2 views
Skip to first unread message

Brian Jensen

unread,
Jul 13, 2009, 3:09:42 PM7/13/09
to resource_controller
I have a LettersController with all my resource_controller logic in:

class LettersController < ApplicationController
resource_controller

#Logic in here
end

class FailedEnrollLettersController < LettersController
belongs_to :stay
#Empty class for now
end

When I point a browser to : http://localhost:3000/stays/1/failed_enroll_letters/new

I get the error:

Processing FailedEnrollLettersController#new (for 127.0.0.1 at
2009-07-13 21:07:47) [GET]
Parameters: {"stay_id"=>"1",
"authenticity_token"=>"Y52hl5P1enWxxLRURWv7YgPcOnyHknyeLNwDiiDKHIM="}
Stay Columns (1.7ms) SHOW FIELDS FROM `stays`
Stay Load (1.6ms) SELECT * FROM `stays` WHERE (`stays`.`id` = 1)

NoMethodError (undefined method `letters' for #<Stay:0x3edc9e0>):


Rendered rescues/_trace (125.1ms)
Rendered rescues/_request_and_response (0.3ms)
Rendering rescues/layout (internal_server_error)

The LettersController is just a resource_controller I want multiple
controllers to inherit from to keep things dry, so its not in the
routes.rb

Brian Jensen

unread,
Jul 14, 2009, 10:05:21 AM7/14/09
to resource_controller
Nested resources ofcause, not attributes.

James Golick

unread,
Jul 14, 2009, 5:47:47 PM7/14/09
to resource_...@googlegroups.com
Have you declared that Stay has_many :letters?

Brian Jensen

unread,
Jul 16, 2009, 5:16:37 AM7/16/09
to resource_controller
No because it hasnt.

There is no Letter model. I just have a LettersController where all
the logic from CustomLettersControllers, ReviewLettersController is
in. And the two controllers inherit from the LettersController.

Thanks in advance.
Brian

James Golick

unread,
Jul 16, 2009, 9:40:22 AM7/16/09
to resource_...@googlegroups.com
Well, when you say belongs_to :something, resource_controller expects to be dealing with a hirearchy of active record models. If you haven't got a hirearchy of activerecord models, you need to either implement methods that mimic them, override the appropriate methods in your controller, or implement the controllers by hand.

- James
Reply all
Reply to author
Forward
0 new messages