1. If your logic code that interacts with database is complicated, you should make it as a class method so that this method could be reusable by other developers in the team. You can return true/false to indicate this process is successful or failed if you don't want any validation errors object. You can also return object/an array of object to get validation errors.
2. Don't use
render :update do |page|....end
which is the bad thing because it returns a javascript code to the browser. And don't use link_to_remote :update => "id"
because this code also generates javascript code back to the browser. Instead, use render :partial => 'update'
to render the plain html code back to the browser and use oncomplete callback to replace the old content with the new result such as: document.getElementById('id').innerHTML = request.responseText;
2 comments:
About 2:
Do you mean not using RJS templates at all? Sometimes, it's very convenient.
And, why return javascript is bad?
Well, it depends on yourself whether it benefits you more. Personally, when the server always send back with javascript code this way, it makes my web application coupling to this resource.
Post a Comment