Answer the question
In order to leave comments, you need to log in
Does anyone know why Rails render_to_string doesn't work as it should?
Hello. I'm trying to solve the problem for the third day. It is necessary to render the template on the rails into a string, there is a method render_to_string and render_to_body. It needs to be rendered because this line should be sent to the browser sse.write.
s = render_to_string(partial: 'comment', formats: [:html], locals: {comment: comment})
b = render_to_body(partial: 'comment', formats: [:html], locals: {comment: comment})
s = render_to_string(partial: 'comment', formats: [:html], locals: {comment: comment}).gsub("\n","")
Answer the question
In order to leave comments, you need to log in
I don’t see any problem at all in your question.
Although I’m not an expert in second rails, I think I won’t be wrong if I assume that from version 2.3.8, as you can see, if there were any shortcomings in this method, they have been fixed :)
What is the problem ? Is it that console.log() should output line breaks (\n) instead of line breaks, actually ? So the problem is that you are trying to interpret the right data incorrectly.
What exactly is your task now?
Here, either delete line breaks by hand, if I'm not mistaken in SSE, it is a field separator, or escape it. Or (IMHO the correct option) is to rewrite communication to JSON, and on the client side to render the received data into a template.
Here is a good example on this topic: www.sitepoint.com/mini-chat-rails-server-sent-events
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question