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 7956917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:08:21+00:00 2026-06-04T04:08:21+00:00

I have a js.erb file with the following code but I can’t seem to

  • 0

I have a js.erb file with the following code but I can’t seem to properly escape the javascript for the link_to helper method. I think it has something to do with the quotation marks around Edit.

$('#microposts').prepend('<div class="micropost"><h3>' +  "<%= j @user.email %>" + '</h3>    <h3>Posted ' + "<%= j time_ago_in_words(@micropost.created_at) %>" + ' ago</h3><p>' +  "<%= j     @micropost.content %>" + '</p><p>' + "<%= j link_to "Edit",      edit_user_micropost_path(@micropost) %>" '</p></div>');
$('#new_micropost')[0].reset();
$('#micropost_count').html('<%= Micropost.count %>');

On a side note, how would I animate this?

  • 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-06-04T04:08:23+00:00Added an answer on June 4, 2026 at 4:08 am

    It’s possible this isn’t exactly the answer you’re looking for, but I would humbly suggest that this isn’t the right approach and the difficulty of escaping this properly is just a symptom of the approach being too complex.

    I know what you’re doing here might actually be par for the course (according to some Rails developers), but I see this as a inefficient, and worse, too complex (and therefore difficult to maintain). Presumably some AJAX call has been made and received this dynamically generated response containing an imperative (commands to DO something; in this case, commands to modify the DOM) implemented in JavaScript. Why not have one static chunk of JavaScript loaded when the page initially loads that knows how to take a small snippet of DATA and render it appropriately?

    What you’d then do is return JSON instead of an imperative chunk of script. Your static JavaScript method would modify the DOM by:

    1. Copying a hidden snippet of easy-to-maintain HTML that’s embedded on that page.
    2. Doing a find/replace on the copy to “fill in the blanks” with data from the JSON structure you got from the AJAX call.
    3. Prepend the collection with the new snippet of HTML.

    Think this would be more straightforward with much easier maintenance.

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

Sidebar

Related Questions

I have the following code in an ERB file: <table border=1> <% @lists.each do
In my Ruby on Rails code, I have the following edit.html.erb file for tasks:
I have the following code in my application.erb file in my layouts directory. I
I have the following code in my .html.erb file that work just as expected:
I have the following code in a .erb file: <% embed='<a href=http://someurl.com/whatever>#{@webcast.name}</a>'%> <p id=embedCode>
I have an .erb file where I'd like to return the following text: Name
I have the following in a html.erb file: <%= @location_list = [['test',2]] %> <script
I have this code in a .html.erb file: <script src=http://connect.facebook.net/en_US/all.js#xfbml=1></script> <script> FB.Event.subscribe('edge.create', function(response) {
I have the following html.erb code that I'm looking to move to Haml: <span
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for

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.