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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:14:12+00:00 2026-05-21T05:14:12+00:00

I have successfully installed jquery-rails in my rails 3 test app. I already had

  • 0

I have successfully installed jquery-rails in my rails 3 test app. I already had it working. Can somebody pls point out to me how to make this jquery code I got from Sreekumar yesterday to work on my rails 3 test app.

Here is the jquery code and I placed this on application.js:

$(document).ready(function() {

        $('#table_list').find('tr>td').hover(function() {
            //$(this).css("background-color", "green");
            $('table_list').addClass('highlight');
        }, function() {
            //$(this).css("background-color", "inherit");
            $('table_list').removeClass('highlight');
        });
        $('#table_list  tr:even').addClass('even');
        $('#table_list tr:odd').addClass('odd');

});

The objective of this code is to make the tables row color alternate and highlight the selected row. Alternating the row color works perfectly fine, however, the highlight is not working.

Here is the rails 3 code in index.html.erb:

<h1>Listing Ninjas</h1>

<table id="table_list">
 <tr>
  <th>Name</th>
  <th>Rank</th>
  <th>Village</th>
  <th>Country</th>
  <th></th>
  <th></th>
 <th></th>
</tr>

<% @ninjas.each do |ninja| %>
 <tr>
  <td><%= ninja.name %></td>
  <td><%= ninja.rank %></td>
  <td><%= ninja.village %></td>
  <td><%= ninja.country %></td>
  <td><%= link_to 'Show', ninja %></td>
  <td><%= link_to 'Edit', edit_ninja_path(ninja) %></td>
  <td><%= link_to 'Destroy', ninja, :confirm => 'Are you sure?', :method => :delete %></td>
 </tr>
<% end %>
</table>

<br />

<%= link_to 'New Ninja', new_ninja_path %>

And here is my css code which is in a separate file application.css:

#table_list{
 border: solid 1px #666;
 border-collapse: collapse;
 margin: 10px 0;
}

#table_list th{
 font-size: 12px;
 color: #FFF;
 background-color: #404C99;
 padding: 4px 8px;
 padding-bottom: 4px;
 text-align: left;
}

#table_list .highlight {
 background-color: yellow;
}

#table_list td {
 font-size: 12px;
 padding: 2px 6px;
}

#table_list .even td {
 background-color: #E3E6FF;
}

#table_list .odd td {
 background-color: #D1D8F6;
}

All of the 3 codes are in separate files.

I’m kinda new to rails and jquery. Im still a beginner. Pls be patient…

  • 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-21T05:14:13+00:00Added an answer on May 21, 2026 at 5:14 am

    This might not answer your question, but there is a much simpler way to achieve even/odd color table, using the cycle command

     @items = [1,2,3,4]
      <table>
      <% @items.each do |item| %>
        <tr class="node <%= cycle("even", "odd") -%>">
          <td>item</td>
        </tr>
      <% end %>
      </table>
    

    Hope this at introduces you to a cool Rails utility

    link : Converting Rails 3 to Rails 2: helpers with blocks

    once u are able to add odd/even to tr , you dont have to use jquery for this purpose simple css is enough

    .odd{
    background-color:#cccccc;
    }
    .even{
    background-color:#ffffff;
    }
    .node:hover{
    background-color:#ff0000;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just successfully installed CakePHP and I see that I can edit the
I have successfully installed SVN on a Windows XP machine and can connect to
I have successfully installed mercurial on media temple grid server. But I can not
I have successfully installed sshd on cygwin. I can ssh to it from within
I have successfully installed the Cycle plugin for Jquery and have my banners cycling
I have successfully installed dotnetnuke 6 on localhost and is working fine but when
I have successfully installed Eclipse and the Android SDK on Fedora 16. However, when
I have successfully installed Oracle 11g R2 version. I don't have good knowledge about
I am an Emacs and Common Lisp novice. I have successfully installed SLIME in
i have successfully created distribution profiles and installed on my xcode organiser, but this

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.