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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:11:26+00:00 2026-06-02T23:11:26+00:00

I have a block like : – competitors.each do |competitor| %dl %dt … %dd

  • 0

I have a block like :

      - competitors.each do |competitor|
        %dl
          %dt
            ...
          %dd
            %span{:id => "#{competitor['watchers']}"}= "#{((competitor['watchers']*100.0)/30000).round.to_f}%"

note that it generate dinamic CSS id, one each block clicle, resoulting html is a list of different dd –> span –> id number :

<dl>
  <dt>
    ...
    <dd>
      <span id="774">93.0%</span>
    </dd>
  </dt>
</dl>
<dl>
  <dt>
    ... 
    <dd>
      <span id="13774">46.0%</span>
    </dd>
  </dt>
</dl>

I want to “dinamically” associate “custom CSS snippets”, to the different css ids ( #13774 #774 ), something like :

:javascript
  $("##{competitor['watchers']}").css({ width: "#{((competitor['watchers']*100)/30000)}px" });

How can I call ajax (in Rails 3.2.3 ‘:remote => true’ ) without link_to kind of helpers ?

Untill now I tried just calling JS from inner block like :

      - competitors.each do |competitor|
        :javascript
          $("##{competitor['watchers']}").css({ width: "#{((competitor['watchers']*100)/30000)}px" });
        %dl
          %dt
            ...
          %dd
            %span{:id => "#{competitor['watchers']}"}= "#{((competitor['watchers']*100.0)/30000).round.to_f}%"

but it doesn’t work, the code is never injected into the DOM.

  • 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-02T23:11:27+00:00Added an answer on June 2, 2026 at 11:11 pm

    It looks like you’re trying to show some kind of bar graph, and in that case, I would suggest the following (I’m assuming you are using jQuery as that’s what’s tagged):

    Change your block to add a unique class to each span. This gives you style benefits later.

    %dd
            %span{:id => "#{competitor['watchers']}", :class => "progress-bar"}= "#{((competitor['watchers']*100.0)/30000).round.to_f}%"
    

    Then you should be able to use some jQuery at the bottom of the page to select each one, and do some basic math on it:

    $('span.progress-bar').each(function(index,element){
        var num = $(element).attr('id'); // get element id
        var width = parseInt(num * 100 / 30000); // do your math, then get the integer value for width
        $(element).css('width',width+'px'); // set width
    }
    

    I know you were looking for ajax, but unless I’m missing something, this should come close to solving your issues as documented.

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

Sidebar

Related Questions

If I have a textarea block like so... <textarea name=myTextArea cols=100 rows=20 readonly=readonly> ..
Say I have a block like this: <% @help_sections.each do |section| %> <li><%= section.name
I have a simple html block like: <span id=replies>8</span> Using jquery I'm trying to
I have a block like this: Blah.where(....).each do |b| # Code here end I
I have oracle block like DECLARE TYPE emp_array IS VARRAY(100) OF VARCHAR2(30); VAR_PRESENTADDRESS1 varchar2(100);
I have two block (like Block1 and Block2) and I have to display one
I have a describe block like this: describe Documents do subject { page }
In javascript, If i have a text block like so Line 1 Line 2
If I have a block of code like this: def show @post = Post.find(params[:id])
I have a try catch and finally block like this. Client client = new

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.