I am using rails 5.1, I have a controller, when I try to render to a string I am getting an empty string
def pdf_string
path = Rails.root.join("/app/views/menu/recipe_card.pdf.erb").to_s;
render_to_string(
:file => path,
locals: get_pdf_locals
)
end
But if I do
ActionController::Base.new.render_to_string(
:file => path,
locals: get_pdf_locals
)
I am getting the view rendered. The problem is that using ActionController::Base.new inside my controller seems kinda odd, and the view is not having access to helper methods. Any idea why the render_to_string of my controller is returning emtpy string while the ActionController::Base.new.render_to_string is rendering correctly?
pry-byebugto set a breakpoint and step into the method to see whether it maybe was overriden somewhere?pdf_stringmethod defined? in the controler or in a helper file? it looks like you are defining it inside a helper file, which gets included in the view which does not have a render_to_string method, you can define it on the controller and add ahelper_method :pdf_stringline after it so that's used in the right context