rails 3.1 render_to_string returning empty string

from a controller method, i'm trying to capture the output of rendering a template from another controller.

the view file is located here:

path/to/show.html.erb

in my controller i have:

def create
  html_string = render_to_string :template => 'path/to/show'
  raise 'html string is empty!' if html_string.empty?
  # do some other stuff
end

the view file is very simple, just containing the text 'foo'.

i'm not getting any error about rails not being able to find the show.html.erb file, but html_string is empty, and the error is raised.

i'm seeing this behavior when running the create method through an rspec controller test. i haven't tried the code through the rails server yet.

does anyone see anything i'm missing here?

Answers


this turns out to be due to my controller spec missing the important line:

render_views

Need Your Help

Trouble loading assembly: 'Microsoft.Practices.EnterpriseLibrary.Common'

asp.net .net visual-studio-2008 exception runtime-error

I have a VS 2008 solution whose projects are making use of a number of the Microsoft.Practicies libraries.

How best to integrate several systems?

legacy-code system-integration

Ok where I work we have a fairly substantial number of systems written over the last couple of decades that we maintain.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.