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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:09:15+00:00 2026-05-23T07:09:15+00:00

I have a .js.erb file that has the following line $(#<%= user#{current_user.id}_following %>).html(<%= escape_javascript(link_to(pluralize(@count,’tag’),

  • 0

I have a .js.erb file that has the following line

$(“#<%=
“user#{current_user.id}_following”
%>”).html(“<%=
escape_javascript(link_to(pluralize(@count,’tag’),
user_tags_path(current_user))) %>”)

It displays

<a href=/users/1/tags>1 taga>

Instead of

1 tag

This used to work when I was running rails 3.0.4 but now it doesn’t now that I’m running rails 3.0.8. I found that I needed to add .html_safe in other places that I had been using auto_link or I would get the same problem.

How do I get it so that it won’t escape this html?

  • 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-23T07:09:16+00:00Added an answer on May 23, 2026 at 7:09 am

    I never liked interpolating your JS with ruby like this. It always leads to hard to understand hairyness.

    Instead, dump your data into JS on it’s own as JSON, then simply use the data as native javascript.

    var user = <%= {
      :id => current_user.id,
      :path => user_tags_path(current_user),
      :link_text => pluralize(@count,'tag'),
    }.to_json %>;
    
    var link = $('<a>').attr('href', user.path).text(user.link_text);
    $('#user' + user.id + '_following').html(link);
    

    Which, in my opinion, is far more understandable and completely dodges any HTML issues since the HTML is not in your ruby expression at all.

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

Sidebar

Related Questions

I have the following in a html.erb file: <%= @location_list = [['test',2]] %> <script
I have an erb file named index that has a form in it. As
In my Ruby on Rails code, I have the following edit.html.erb file for tasks:
I have an .erb file where I'd like to return the following text: Name
In my erb file, I have the following code in the body tag: <%
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) {
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
I built a .erb file that has a bunch of variables listed in it.
I have a large Ruby on Rails form that has the following partial view
So a user has many colleges (that they have attended), and a college belongs

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.