RameshVel
RameshVel

Reputation: 65877

rails render_to_string giving errors with partial view

I am getting ActionView::MissingTemplate error when using render_to_string method with partial views, below the code

 bizz = render_to_string(:partial => "biz_new",:layout => false)

Even though i have explicitly specified :layout => false, i am getting the MissingTemplate error always.

But render_to_string with normal views works fine in the same project. what could be the reason?

below the stack trace

ActionView::MissingTemplate (Missing partial businesses/biz_new with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:text, "/"], :locale=>[:en, :en]} in view paths "/home/ramesh/works/xxx/app/views", "/home/ramesh/works/xxx/vendor/plugins/asset_packager/app/views"):

Upvotes: 8

Views: 8259

Answers (5)

Wil Gieseler
Wil Gieseler

Reputation: 2173

I had a problem where I was using formats: "html" but needed to be changed to a symbol like formats: :html.

Upvotes: 0

Mike Kijewski
Mike Kijewski

Reputation: 539

Try

 render_to_string("_biz_new", :formats => [:html], :layout => false, :locals => {:biz => @biz})

render_to_string needs the starting underscore and the .html extension.

Upvotes: 11

marcelo
marcelo

Reputation: 41

As Mike Kijewski mentioned, you can include the underscore at the beginning of the partial name, but if you use the .html in the end you will get a deprecation warning. A more straightforward way is this:

render_to_string(:partial => "folder_name/_partial_name", :formats => [:html], :layout => false, :locals => {:a_needed_argument_for_the_partial => @arg})

Upvotes: 4

Anthony Sekatski
Anthony Sekatski

Reputation: 51

Had similar issue.

I found a solution:

render_to_string(model, :formats => [:html])

Upvotes: -1

Luke Cowell
Luke Cowell

Reputation: 703

It looks like rails is expecting the file to be in format txt. What's the file named ? Try naming it:

_biz_new.txt.erb 

-or-

businesses/_biz_new.txt.erb

Upvotes: 2

Related Questions