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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:06:40+00:00 2026-05-29T18:06:40+00:00

Hi I am using jQuery with rails 3 to display or not the same

  • 0

Hi I am using jQuery with rails 3 to display or not the same div with different data for each iteration. This is my code:

    <% @event.event_criterias.each do |event_criteria| %>
    <p>
    <table>
    <% cont = 1 %>
    <% form_for event_criteria do |f| %>

        <%= f.hidden_field :event_id %>
        <%= f.hidden_field :is_free %>
        <%= f.hidden_field :is_exclusive %>

        <tr>
            <td width="150px">
                <%= f.label :name, event_criteria.name%>        
            </td>
            <td>
                <%= f.text_field :name%>
            </td>   

        <td><%= f.submit "Update name", :disable_with => 'Updating name...'%></td>
        <td><%= link_to '[delete]', event_criteria, :confirm => 'Are you sure?', :method => :delete %></td>

        <% if !event_criteria.is_free and !event_criteria.is_exclusive %>
            <td>Show options <%= check_box_tag 'show_event_criteria_options'+cont.to_s, 'event_criteria_options'+cont.to_s, false, :class => 'check_buttons' %></td>

            <% cont += 1 %> 
            <td> <%= link_to 'Create options', new_event_criteria_option_path(:event_criteria_id => event_criteria.id) %> </td>
        <% end %>

        </tr>
        </table>

        <div id="event_criteria_options"+<%= cont.to_s%> style="display: none;" >
            <%= link_to 'Create option', new_event_criteria_option_path(:event_criteria_id => event_criteria.id) %>
            <% if event_criteria.is_free == false and event_criteria.is_exclusive == false %>
            <p>Options: </p>
            <table>
            <% event_criteria.event_criteria_option.order('value').each do |event_criteria_option| %>
              <tr>
                <td><%= link_to event_criteria_option.value, event_criteria_option_path(event_criteria_option) %></td>
                <td><%= link_to '[delete]', event_criteria_option, :confirm => 'Are you sure?', :method => :delete %></td>
              </tr>
            <% end %>
            </table>
            <% end %>
            <% end %>
        </div>

        <% if !event_criteria.is_free && !event_criteria.is_exclusive && event_criteria.event_criteria_option.size == 0 %>
            <p><i> No options defined! </i></p>
        <% end %>


<% end %>

<% end %>

And my jQuery code:

    $(document).ready(function(){
   $(".check_buttons").click(function(){
    var divname = this.name;
    var divvalue = this.value;
      if ($("#"+divname).attr("checked")){
         $("#"+divvalue).show("slow");
      }else{
         $("#"+divvalue).hide("slow");
      }
   });
});

The problem is that only displays div id= event_criteria_option+<%=cont.to_s%> when I check the first checkbox. When i check toher checkboxes it doesn’t displays anything.
What is the mistake?

  • 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-29T18:06:41+00:00Added an answer on May 29, 2026 at 6:06 pm

    The following line

    <div id="event_criteria_options"+<%= cont.to_s%> style="display: none;" >
    

    should be

    <div id="event_criteria_options<%= cont.to_s%>" style="display: none;" >
    

    Because you need the ‘cont.to_s’ inside the HTML id double quotes.

    Also on a side note, you should know that ruby conditional “&&” is not the same as key work “and”. You might want to change that in the line that reads like:

    <% if !event_criteria.is_free and !event_criteria.is_exclusive %>
    

    Read more about that here.

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

Sidebar

Related Questions

I'm using jQuery with rails and have the following piece of code $('#related').html(<%= render
This is a Rails 3 project using jQuery 1.4.4. I have an index action
I have started using jQuery and rails. I have made a simple form that
I am using jQuery with rails. I am trying to make a PUT request
I'm using rails, but doing all my Javascript unobtrusively using jQuery in application.js .
I am using Rails and jQuery, making an ajax call initiated by clicking a
Using jQuery, how do you bind a click event to a table cell (below,
Tried doing http://davidwparker.com/2008/09/17/site-wide-announcements-in-rails-using-jquery-jgrowl/ Am really bad with JS. Think I am messing up on
I'm having trouble getting JSON data from my Rails app to display on a
I am using jQuery in my Rails application. I wanted to add a expand

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.