<HTML>
<HEAD>
<TITLE>Re: [LRUG] Moving logic from view to controller/model</TITLE>
</HEAD>
<BODY>
<FONT FACE="Lucida Grande, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'><BR>
One of the guiding principles of Rails is Skinny Controller Fat Model.<BR>
I always endeavour to locate which aspects can be considered business logic and pushed into the model and which is just for the view and should be in a helper.<BR>
Presenter Patterns might also have they’re place:<BR>
<a href="http://blog.jayfields.com/2007/03/rails-presenter-pattern.html">http://blog.jayfields.com/2007/03/rails-presenter-pattern.html</a><BR>
<BR>
I don’t think you need  <BR>
<%= hidden_field_tag "user[role_ids][]", "" %><BR>
<BR>
The logic around destruction of the admin & System Administrator relationship should definitely be in the model.<BR>
<BR>
The way I think about it is that you should be able to interact with the models directly through the console and get the same business behaviour as if you were interacting via a browser.. <BR>
I fact I always build my apps console and model first,  then controller, then view.<BR>
<BR>
<BR>
<BR>
On 25/7/08 18:14, "Kevin Fullerton" <kevin.fullerton@shotgun-suicide.co.uk> wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Lucida Grande, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'>Hi,<BR>
 <BR>
I’ve got a little pet project I’m working on with RoR and I’ve added some logic to the view that I know should be in either the controller or the model.<BR>
 <BR>
The offending code is<BR>
 <BR>
<p>Roles<br/><BR>
<%= hidden_field_tag "user[role_ids][]", "" %><BR>
<% for role in Role.find(:all) %><BR>
<% if @user.login == 'admin' && role.role_name == 'System Administrator'  %><BR>
  <%= check_box_tag "user[role_ids][]", role.id, @user.roles.include?(role), :disabled => true %><BR>
  <%= hidden_field_tag "user[role_ids][]", role.id %><BR>
<% else  %><BR>
  <%= check_box_tag "user[role_ids][]", role.id, @user.roles.include?(role) %><BR>
<% end  %><BR>
<%= role.role_name %><BR>
<% end %><BR>
</p><BR>
 <BR>
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)<BR>
 <BR>
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 J<BR>
 <BR>
Many thanks<BR>
 <BR>
Kevin Fullerton<BR>
<BR>
<HR ALIGN=CENTER SIZE="3" WIDTH="95%"></SPAN></FONT><FONT SIZE="2"><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:10.0px'>_______________________________________________<BR>
Chat mailing list<BR>
Chat@lists.lrug.org<BR>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><BR>
</SPAN></FONT></FONT></BLOCKQUOTE><FONT SIZE="2"><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:10.0px'><BR>
<BR>
</SPAN></FONT></FONT><FONT FACE="Lucida Grande, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'>-- <BR>
Anthony Green<BR>
Client Side Developer<BR>
Future Media & Technology for BBC Audio & Music Interactive</SPAN></FONT>
<br/><font face="Times New Roman" size="3"><a href="http://www.bbc.co.uk">http://www.bbc.co.uk</a><br/>This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated.<br/>If you have received it in error, please delete it from your system.<br/>Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately.<br/>Please note that the BBC monitors e-mails sent or received.<br/>Further communication will signify your consent to this.</font></BODY>
</HTML>