I am new to rails and want to learn the ‘best practices’ up front. So I
have a few questions and hope someone can help:
- Using Ajax to update a div. The remote_function must call an action
on a controller. This causes me two problems:
1.a The action is only ever used by the ajax call, but can now be
accessed through the browser. I want ajax to call a method/action that
is not accessible to a user.
1.b The action must replace the entire div. That is fine, but now I
have duplicate presentation logic. The view renders the div with
something like ‘select’ helper, and now the action called by ajax has to
do the same - but I cannot use the ‘select’ helper in the controller
(not that I can find) so I have to create the and tags
with more verbose ruby logic.
I know ruby on rails does not like you to repeat yourself so I have no
doubt I am doing something wrong. How can I have only one piece of
presentation logic shared by both the controller action, and the view?
And, how can I use the ‘select’ helper in the action instead of manually
coding the tags. Or, is there a better approach I am not seeing?
- Business logic. I am fairly new to MVC. Where does the business
logic sit? I am sure it is not in the view (when therfore also rules
out the view helpers in my mind), and it does not seem right in the
controller since each public method is accessible through the browser.
So I am left assuming the bulk of the application is implemented in the
model?. I want to have the appropriate level of separation between
layers. Can someone tell me if I am on the right track?