Forum: Ruby on Rails Controller and Model Responsibilities

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Martin G. (Guest)
on 2006-04-26 16:20
(Received via mailing list)
Hi everyone,

I am wondering what code has to go into the controller and what into
the model. Generally I would think that all operations that keep the
model in a proper state should be done within the model, and the
controller should only provide the actions necessary to carry out the
application's use cases. Am I right so far?

My situation is the following. Whenever an admin performs the action
of creating a new record of questionnaire type (i.e. a new
questionnaire for a client), it also needs to create records in the
tables storing the questionnaire input data. My first guess was that
this functionality should be implemented in the questionnaire model
class, as it is the models responsibility to keep itself in a proper
state. However, I get an "uninitialized constant" error, when I try to
call from within the Questionnaire model
class. If I do the same from within the controller, and declare model
:questionnaire_input_data then everything works fine.

The problem is that in my opinion this pollutes controller code very
much, apart from that, it's simply not the controllers job to perfrom
these operations.

What I basically need to do is create new instances of othe model
classes from within a model class. There must be a way this can be
done, right :)?

This topic is locked and can not be replied to.