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

  • SEARCH
  • Home
  • 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 6142905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:27:03+00:00 2026-05-23T18:27:03+00:00

I am outfitting a rails 3 app (version 3.0.9) to use AJAX and jQuery

  • 0

I am outfitting a rails 3 app (version 3.0.9) to use AJAX and jQuery to fluidly handle user posts. I would like for a #users_info div to be refreshed following the post submission. I can get this to work, but the contents of the div don’t render properly. Specifically, the jquery code in create.js.erb:

 $("#right_bar").html(
'<%= escape_javascript(render :partial => 'shared/user_info') %>'
 );

Results in the user info div outputting:

 <div id=user_info> <h1>    
 <a href=/users/101>Example Usera> h1>  
 46 posts <br>  
 4 discussions <br> 
 Following 2 topics <br>    
 Joined 8 days ago.div>

Note how the escape_javascript function removes all leading angle brackets on end tags in html ( becomes a>, become h1>). How can I force the escape_javascript to avoid doing so? I think this is all the relevant code, but can post more if needed.

UPDATE

I was wondering if maybe using to_json would be part of the solution. the code:

<%= escape_javascript((render :partial => ‘shared/user_info’).to_json) %>

results in the html tags not being destroyed. However, i don’t know how to convert back from json to output the desired html. Just thought this might be the right start, but i’m not sure how to finish it

  • 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-23T18:27:04+00:00Added an answer on May 23, 2026 at 6:27 pm

    I found a solution. just wrap the contents of escape_javascript(contents) in escape_javascript(“#{}”).

     $("#right_bar").html(
    '<%= (escape_javascript("#{(render :partial => 'shared/user_info')}")).html_safe %>'
     );
    

    I added the html_safe at the end so that rails would not make the angle brackets literal. Now the html tags go through properly, and everything renders properly in the browser.

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

Sidebar

Related Questions

I'm using acts_as_taggable_on in my rails app. I'd like these tags to show up
I am using Ruby on Rails 3.0.7 and I would like to populate the
I have the following in my Rails 3 app photo view: <% for version
I'm outputting html that's all crushed together, and would like to convert it to
I could use your helping creating a valid JSON object in Rails. Here is
I have a partial in my rails app that loads the vote form (It's
I'm using Inherited Resources for my Rails 2.3 web service app. It's a great
I have installed the less-rails gem as I am keen to use the colour
When outputting user input, do you only use htmlspecialchars() or are there are functions/actions/methods
Technically it should iterate from 0 to rangeLength outputting the user name of the

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.