comopasta Gr wrote in post #999960:
> Hi,
>
> I'm in trouble with encoding again.
> I have a text area. Where I can enter sentences. And when a sentence
> that contains multiple lines is typed I get this into the DB:
>
> (json serialized)
>
> --- "{\"text\":[\"line one\\r\\nline two\"]}"
>
> Ok. When I take it from the db I see it like this in the controller:
> {"line one\r\nline two"=>"text"}
> (I have done something in between to change the order but that's
> irrelevant)
> But you can see the \r\n in it.
>
> The thing is that in the view I need to pass it via javascript to a
> function that re-creates the text area dynamically.
>
> But the function gives the error: "Uncaught SyntaxError: Unexpected
> token ILLEGAL"Well now I think I fixed this. Nothing to do with json. More with common sense. Mine. In the controller I just added again the double \ @value = det.last[i].gsub!(/\n/, '\\n') @value = det.last[i].gsub!(/\r/, '\\r') Then @value can be used in the view and the line breaks stay in place. No JS error and no need to do any CGI::escape to keep them anymore. And no problems with accents since I don't use CGI::escape anymore. Cheers. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

