Forum: Ruby on Rails Controller and Model Responsibilities

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5e518814b76962fdd1ad0e74dfac5ea7?d=identicon&s=25 Martin Gamsjaeger (Guest)
on 2006-04-26 14: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 QuestionnaireInputData.new 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 :)?

cheers
Martin
This topic is locked and can not be replied to.