Forum: Ruby on Rails where i should put it ? controller, model or both?

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.
4f384e9f3e8e625aae72b52658323d70?d=identicon&s=25 usser (Guest)
on 2007-02-04 01:26
hi, I've to check something like: the user can have the same object in
the wish list only once.
the user put the object X in the wish list - ok
the user try to add the object X to the wish list another time --> not
ok, the user is redirected to another url with a notice
because i use the session and notice i think i've to put the control in
the controller(because the model doesn't know anything about session,
redirect and notice), but i should put it also in the model?
usually what kind of controls i've to write in the controller and when
in the model?
2f9a03aa0fcfe945229cb6126eda2cb2?d=identicon&s=25 Philip Hallstrom (Guest)
on 2007-02-04 01:34
(Received via mailing list)
> in the model?
> thanks

If your business logic mandates that the wish list has to have a unique
list of items, then that should go in your model so that regardless of
where you manage the wish list the rules hold up.

If it's not mandated, but only in this one instance, then put the check
the controller.

Me, I'd put it in the model, and return an error if it's duplicated that
your controller can use to redirect somewhere else.

This topic is locked and can not be replied to.