Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7595055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:34:33+00:00 2026-05-30T21:34:33+00:00

I am trying to render a haml file in a javascript response like so:

  • 0

I am trying to render a haml file in a javascript response like so:

$('#<%= @email.unique_name %> .preview .mail_content').html('<%=j render( :file => "user_mailer/#{@email.key}") %>');

An example of the file that would render is:

- variables = { :contact_first_name => @contact.first_name, :user_full_name => @user.name, :user_first_name => @user.first_name }

= @email.intro_html(variables)

%p= "Please click the link below to go directly to the results of #{@user.first_name}'s assessment. You can also access an analysis of that assessment from that page."

%p= share_results_url(@token)

= @email.conclusion_html(variables)

Now two problems occur for me if we look at the javascript that is given in the response:

$('#launch_share_results .preview .mail_content').html('\u003Cp\u003EHi Jane,\u003C/p\u003E
\u003Cp\u003EJohn Smith has taken a 360(deg) \u003Cspan style=color:red;\u003E\u003Cstrong\u003ENo such variable available!\u003C/strong\u003E\u003C/span\u003E assessment through myLAUNCHtools.com and would like to share the results with you.\u003C/p\u003E
\u003Cp\u003EPlease click the link below to go directly to the results of John's assessment. You can also access an analysis of that assessment from that page.\u003C/p\u003E
\u003Cp\u003Ehttp://lvh.me:3000/assessments/results/1\u003C/p\u003E
\u003Cp\u003EThank you in advance for your time and interest in John\u0026#8217;s leadership.\u003C/p\u003E
\u003Cp\u003ESincerely,\u003Cbr /\u003E
Launch\u003C/p\u003E
');

The major problem is that the response has newlines in it. This breaks the request. I presumed using j in front of my render call would fix that, but it doesn’t.

The other problem is that on the third line of the haml file I have:

#{@user.first_name}'s assessment

and that apostrophe also breaks the request. (I know this because I used a javascript function to delete all the new lines and the request was still broken until I took out that apostrophe as well)

Is there a simpler way to clean up the javascript response than chaining on javascript functions to clean it up for me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:34:34+00:00Added an answer on May 30, 2026 at 9:34 pm

    I experienced a similar problem. Problem exists because both methods, ‘escape_javascript’ and ‘json_escape’ are aliased as ‘j’ (https://github.com/rails/rails/pull/3578).

    Solution:
    Use ‘escape_javascript’ instead of ‘j’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to render a calendar with Rails and Haml . The dates used
In haml, how do I render the following incredibly basic HTML: <p>Results found for
When trying to render a Django template file in Google App Engine from google.appengine.ext.webapp
I am trying to render HTML as it is typed. That is, a user
I am trying to render content generated by a php file in [jQuery Colorbox][1]
I am trying to render the magento contact form into a .phtml file, but
Trying to render html which is passed from a webservice to display in a
I am trying to render a HTML table to display on Windows Mobile 6.0
I'm trying to render a flat Json obect into a tree like <ul> using
I'm trying to render a georss or even kml file produced from geoserver in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.