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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:56:44+00:00 2026-06-04T17:56:44+00:00

As part of an ajax call, I am trying to use embedded ruby to

  • 0

As part of an ajax call, I am trying to use embedded ruby to generate the id portion of a jquery select in a .js.erb file.
Below is how I got it to work, but I had to use a slight of hand and get the javascript in the browser to concat the id to the selector instead of constructing the jquery selector on the server.

$("tr.design#".concat(<%= @form_column.form_row.id.to_s %>)).html("<%= escape_javascript( render(:partial => "form_rows/row") ) %>")

I tried several combinations:

$(<%= escape_javascript("tr.design#" << @form_column.form_row.id.to_s) %>)

$(<%= "tr.design#" << @form_column.form_row.id.to_s %>)

$("tr.design#<%= @form_column.form_row.id.to_s %>")

in each case the selector returned to the client was $(tr.design#17) (without quotes) and therefore was not executed as I wanted on the client, ie jquery didn’t find any matches.

The .html("<%= escape_javascript( render(:partial => "form_rows/row") ) %>") portion was sent to the browser correctly, ie the <%= … %> behaved as expected and the javascript on the browser received nicely formatted, quoted (and escaped) html passed in the .html function.

Anyone got any ideas on how I could avoid the use of .concat in my .js.erb file?

  • 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-04T17:56:46+00:00Added an answer on June 4, 2026 at 5:56 pm

    Like this

    $('#user_<%= @user.id %>').click(blah blah blah);
    

    If you place <%= %> in a js.erb file, that code is evaluated an printed in the resultant JS. You can construct any unique string you want.
    Probably :classname_:id is most common solution.

    By the way, the evaluated code don’t has to be an string. <%=%> calls .to_s for printing. In that example, the @user.id is converted into a string.

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

Sidebar

Related Questions

I am trying to use jQuery's ajax functionality to update data from a web
I am trying to make an Ajax call with jquery, if I put an
I'm trying to call an instance method a() from within a jQuery ajax call.
Trying to find out why this jQuery JS isn't making ajax call though it
We are using jqGrid in local mode and as part of our ajax call
I'm loading part of my webpage using AJAX, in particular jQuery.load() . With this
I am making an ajax request to a file and as part of the
I'm trying to use jQueryUI tabs, loading the Tabs via AJAX. The problem I'm
I have some jQuery with an Ajax call that looks like this: $.ajax({ type:
I've been trying to get this really simple example of using AJAX with JQuery

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.