That's my great doubt.
We have a project in RoR and we are making it more dynamic, using Ajax calls. They want that I put literal JSON in html templates and parse it with eval() in javascript, avoiding to putting exception into Controller to return response as JSON directly.
Example: WhateverControoler#index -> will render views/whatever_controller/index.html.erb (JSON literal in an html template):
{
"Success": "false",
"Date": ("need_login": "true")
}
What I suggest to use in WhateverControoler#index
render :json => (: success => false, :data => (:need_login => true))
Instead of putting it into Controller, they want me to use the template that Controller will render normally to show a literal JSON.
Some controllers have begin/raise blocks that redirects to other places, because of it I need put exceptions to render JSON instead redirct.
if (is_ajax) render :json[..] else redirect_to [..] end
I need an strong reason to avoid it and shows that's wrong.
This make sense? I tried to explain at best I can.
PS: I know that I could use "respond_to do |format|..." but I need as if statments because of the redirects, the code is already messy and they want to avoid messing up even more