render_to_string partial format error in controller

ruby-on-rails, ruby-on-rails-3

Solution

See this question and this issue. Since you're making a JSON request your `render_to_string` is expecting your partial to be `_search_details.json.erb`. You can either provide an additional JSON partial, rename the partial or add this to the partial `<% self.formats = [:json, :html] %>`, or alternatively, try the workaround in the accepted answer to that question.

Problem

I get the below error when running the below code on a controller. Please note the `:formats=>[:json]` in the error, even though `:formats=>[:html]` is passed into render_to_string What am I doing wrong? Any ideas? Actually, the code below worked fine before, not sure what changes influenced this error. Rails version: 3.2.8 btw the template is definitely in place: loc/_search_details.html.erb Bonus question: where can I find the api documentation showing what parameters can be passed to render_to_string and how it works? Error: ActionView::MissingTemplate (Missing partial loc/search_details with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder, :coffee]}. ``` respond_to do |format| format.json { @detail_str = render_to_string(:partial => 'loc/search_details', :layout => false, :formats=>[:html], :locals => {:beer_results => @beer_results}) @list_str = render_to_string(:partial => 'loc/search_list', :layout => false,:formats=>[:html], :locals => {:beer_results => @beer_results}) render :json => {:results => @results_hash, :result_details => @detail_str, :result_list => @list_str } } end ```

Original source

Related problems