Controller and Model Responsibilities

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs