Questions tagged [render-to-string]

58 questions
63
votes
4 answers

React renderToString() Performance and Caching React Components

I've noticed that the reactDOM.renderToString() method starts to slow down significantly when rendering a large component tree on the server. Background A bit of background. The system is a fully isomorphic stack. The highest level App component…
Jon
  • 5,945
  • 4
  • 21
  • 31
46
votes
5 answers

Laravel Error: Method Illuminate\View\View::__toString() must not throw an exception

Have you seen this lovely error while working in Laravel? Method Illuminate\View\View::__toString() must not throw an exception I have seen it and it's incredibly annoying. I have found out two reasons why this error gets thrown. I just want to…
cbloss793
  • 1,555
  • 4
  • 19
  • 30
41
votes
5 answers

How to pass variables to render_to_string?

Trying to do the following @message = render_to_string ( :sender => sender, :template => "template" ) But when accessing @sender in template it turns out to be nil:NilClass. Double checked if I pass the right variable and it's totally…
Arty
  • 5,923
  • 9
  • 39
  • 44
20
votes
2 answers

Why do some floating point numbers appear with a trailing 0

Does anyone know why the numbers 0.001 to 0.009 are rendered to a String with a trailing 0 but other numbers do not. e.g. numbers 0.01 to 0.09 do not. System.out.println(Locale.getDefault()); for (int i = 0; i <= 20; i++) System.out.println(i /…
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
17
votes
4 answers

Rails render_to_string

I am having difficulty with the rails render_to_string function. I have created an app using the --api flag, so i think this may be the issue as i have tested in 'full' rails apps and its works just fine. Essentially i am calling: body_html =…
Dudedolf
  • 505
  • 1
  • 6
  • 18
13
votes
3 answers

render_to_string does not find partials (PDFKit controller response)

Ruby 1.8.7, Rails 3.0.4, PDFKit 0.5.0 I'm trying to create a PDF with PDFKit without using the middleware so I can disable javascript (there's an accordion action in there that hides a lot of info that should be on the PDF). However, whenever I try,…
Chicagogrrl
  • 479
  • 3
  • 10
12
votes
4 answers

How to simplify "render_to_string" in Rails 3?

To render a partial in Rails 3 I do: render 'my_partial', :my_object => my_value To get partial's result as string I do: render_to_string(:partial => 'my_partial', :layout => false, :locals => {:my_object => my_value}) Is this…
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
9
votes
3 answers

How to use SSR with Stencil in a Nuxt 3 Vite project?

In Nuxt 2 I could use server-side rendered Stencil components by leveraging the renderToString() method provided in the Stencil package in combination with a Nuxt hook, like this: import { renderToString } from '[my-components]/dist-hydrate' export…
8
votes
2 answers

can't encode single quote (') using django's render_to_string

i have a problem with django's render_to_string and encoding single quotes. ... = render_to_string('dummy.txt', {'request':request, 'text':text,}, context_instance=RequestContext(request))) why are only these quotes translated to '#39;' and all…
phi
  • 333
  • 5
  • 9
7
votes
2 answers

var_export to string

I have an HTML code in the $output string, this code is delimited by two terms: -startMiniPreview- and -endMiniPreview-. I need to take the part wrapped between those two terms and save it in another string variable. This is what I thought was the…
5
votes
0 answers

render_to_string rails 3.1

I try this: :content => render_to_string(:template => "#{path[:controller]}/#{path[:action]}.html.haml") In my json, but I use kaminari to paginate pages and a receive this error: ActionView::Template::Error (Missing partial kaminari/paginator…
user979029
  • 51
  • 2
5
votes
1 answer

How to render partial in lib ruby class using render_to_string

I am writing a custom tag for Liquid and want to render a partial in the tag. I am assuming I have to use render_to_string but I can't seem to get it to work. I've tried all sorts of things,…
Matt
  • 61
  • 6
4
votes
4 answers

Loading a page into memory in Rails

My rails app produces XML when I load /reports/generate_report. On a separate page, I want to read this XML into a variable and save it to the database. How can I do this? Can I somehow stream the response from the /reports/generate_report.xml URI…
titaniumdecoy
  • 18,900
  • 17
  • 96
  • 133
4
votes
1 answer

Authenticity Token being created differently when using render_to_string

I'm generating a small form through render_to_string and for some reason the CSRF token is not being generated correctly (i.e. it's different from the header and the user is logged out on submit, along with a "Can't verify CSRF token" on the logs).…
4
votes
1 answer

How to create pdf file with layout applied to it. Using pdfkit gem

require 'pdfkit' html = render_to_string(:layout => 'layouts/test_layout' , :action => print_form.html.erb") kit = PDFKit.new(html) send_data(kit.to_pdf, :filename => "Form.pdf", :type => 'application/pdf') above code generates PDF file without…
Ashwini
  • 2,449
  • 2
  • 29
  • 42
1
2 3 4