Rails render_to_string gives partial view errors

I get an ActionView::MissingTemplate when using the render_to_string method with partial views below code

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

Even if I explicitly indicated :layout => false , I always get a MissingTemplate error.

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

below stack trace

ActionView :: MissingTemplate (there is no partial business / biz _new with {: handlers => [: erb ,: rjs ,: builder ,: rhtml ,: rxml] ,: formats => [: text, "/"],: locale = > [: en ,: en]} in the viewing path "/ Home / Ramesh / works / xxx / application / views", "/ Home / Ramesh / works / xxx / supplier / plugins / asset_packager / application / opinions"):

+4
source share
5 answers

Try

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

render_to_string requires an initial underscore and .html extension.

+10
source

It seems that the rails are expecting the file to be in txt format. What did the file name? Try to name it:

 _biz_new.txt.erb 

-or-

 businesses/_biz_new.txt.erb 
+2
source

As Mike Kievsky mentioned, you can enable the underscore at the beginning of a partial name, but if you use .html, you will get an obsolescence warning at the end. An easier way is this:

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

Have you tried to specify a partial path, for example 'bizs / biz_new'?

0
source

Had a similar problem.

I found a solution:

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

-1
source

Source: https://habr.com/ru/post/909800/


All Articles