<br><br><div><span class="gmail_quote">On 1/31/06, <b class="gmail_sendername">Jason Bell</b> &lt;<a href="mailto:jason.b@aanet.com.au">jason.b@aanet.com.au</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I am new to rails and want to learn the 'best practices' up front.&nbsp;&nbsp;So I<br>have a few questions and hope someone can help:<br><br>1.&nbsp;&nbsp;Using Ajax to update a div.&nbsp;&nbsp;The remote_function must call an action<br>on a controller.&nbsp;&nbsp;This causes me two problems:
<br>1.a&nbsp;&nbsp;The action is only ever used by the ajax call, but can now be<br>accessed through the browser.&nbsp;&nbsp;I want ajax to call a method/action that<br>is not accessible to a user.<br>1.b&nbsp;&nbsp;The action must replace the entire div. That is fine, but now I
<br>have duplicate presentation logic.&nbsp;&nbsp;The view renders the div with<br>something like 'select' helper, and now the action called by ajax has to<br>do the same - but I cannot use the 'select' helper in the controller<br>
(not that I can find) so I have to create the &lt;select&gt; and &lt;option&gt; tags<br>with more verbose ruby logic.<br><br>I know ruby on rails does not like you to repeat yourself so I have no<br>doubt I am doing something wrong.&nbsp;&nbsp;How can I have only one piece of
<br>presentation logic shared by both the controller action, and the view?<br>And, how can I use the 'select' helper in the action instead of manually<br>coding the tags.&nbsp;&nbsp;Or, is there a better approach I am not seeing?</blockquote>
<div><br>Use partial view templates. <br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">2.&nbsp;&nbsp;Business logic.&nbsp;&nbsp;I am fairly new to MVC.&nbsp;&nbsp;Where does the business
<br>logic sit?&nbsp;&nbsp;I am sure it is not in the view (when therfore also rules<br>out the view helpers in my mind), and it does not seem right in the<br>controller since each public method is accessible through the browser.<br>
So I am left assuming the bulk of the application is implemented in the<br>model?.&nbsp;&nbsp;I want to have the appropriate level of separation between<br>layers.&nbsp;&nbsp;Can someone tell me if I am on the right track?</blockquote><div><br>
I'm by no means an expert, but I usually divide up my business logic based on what it operates on - if it's a core part of the model, then it goes into the model - validation, complex getters / setters, etc.&nbsp; If it involves the control of the web app in any way (
i.e., deciding where to redirect, picking a partial to display, etc.) it goes in the controller.<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks,<br>Jason<br><br>--<br>Posted via <a href="http://www.ruby-forum.com/">http://www.ruby-forum.com/</a>.<br>_______________________________________________<br>Rails mailing list<br><a href="mailto:Rails@lists.rubyonrails.org">
Rails@lists.rubyonrails.org</a><br><a href="http://lists.rubyonrails.org/mailman/listinfo/rails">http://lists.rubyonrails.org/mailman/listinfo/rails</a><br></blockquote></div><br>