Jul 8, 2011

Stupid Rails3 with Missing template and render_to_string on partial view


render :json=>{:ok=>true ,:new_row=>render_to_string(:partial=>"row",:locals=>{:entity=>entity,:field_set=>SHOW_FIELDS,:is_new=>false}), :entity=> entity}


This gives you a "Missing template" error, even the view exists. I have found that this is because an AJAX request on Rails does not include the view format :html.

In order to fix it, just append .html.


render :json=>{:ok=>true ,:new_row=>render_to_string(:partial=>"row.html",:locals=>{:entity=>entity,:field_set=>SHOW_FIELDS,:is_new=>false}), :entity=> entity}


And it will work.

Stupid Rails 3.0.3