[LRUG] Moving logic from view to controller/model

Matthew Westcott matthew.westcott at torchbox.com
Fri Jul 25 14:49:36 PDT 2008


On 25 Jul 2008, at 18:14, Kevin Fullerton wrote:
> Basically, Role is a habtm join to User – I want to show all  
> available Roles, clearing the habtm association if none are  
> selected, apart from where the user is admin and the Role is System  
> Administrator – that must always be selected (to ensure that no db  
> monkeying is required when the inevitable happens and admin is  
> removed from the System Administrator role)
>
>
>
> So – should this go in the model in a before_save callback or in  
> the controller – my gut says model but wanted to call on the wealth  
> of knowledge here
>

It sounds like the model is most appropriate, yep. You have a  
business rule saying "the admin user shall never be unassigned from  
the 'System Administrator' role", and that rule is meant to hold  
globally, regardless of any particular bit of interface. If on the  
other hand your intention was to say "this bit of interface won't  
allow you to demote the admin user, although there could conceivably  
be another bit of the application which does" then handling it in the  
controller makes more sense.

- Matt


More information about the Chat mailing list