Solved

cycle twice

Posted on 2008-10-10
5
324 Views
Last Modified: 2013-11-13
For some reason when I put two calls to cycle in a loop, neither cycle - something like

<%= cylce("<tr><td>", "<td>")  %>
<%= check_box_tag ...... %>
<%= cycle("</td>", "</td></tr>"  %>

Only the first option of both cycles ever fires.
I tried combining them, but putting a check_box_tag into the single cycle also caused it to not cycle.

Any help would be much appreciated.

Thanks!
0
Comment
Question by:ARACK04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:ozataman
ID: 22688155
Hi,

It seems that you are changing the cycle parameters. Would it be possible to do:

<%= cylce("<tr><td>", "</td></tr>")  %>
<%= check_box_tag ...... %>
<%= cycle("<tr><td>", "</td></tr>"  %>

Also, if what you are trying to do is automate the html tags, you might want to define a helper function as:

def my_check_box_tag(field_name, value, html_options)
  content_tag :tr do
    content_tag :td do
      check_box_tag(field_name, value, html_options)
    end
  end
end

then just call it from the view as

<%= my_check_box_tag(:object, 3) %>

Cheers,
OA
0
 

Author Comment

by:ARACK04
ID: 22688466
Thanks for the reply - the whole point is that I want to create a table with 2 columns, so that's why the cycle parameters are different.

Is there no way to get more than one cycle in the same scope to bahve properly?
0
 
LVL 1

Accepted Solution

by:
ozataman earned 500 total points
ID: 22688501
Well, I you could do that with a helper function as well. But if you're not comfortable, then you could do:

cycle("<tr>","</tr>", :name => 'row')
cycle("<td>","</td>", :name => 'col')
first col
cycle("<td>","</td>", :name => 'col')
cycle("<td>","</td>", :name => 'col')
second col
cycle("<td>","</td>", :name => 'col')
cycle("<tr>","</tr>", :name => 'row')

I still think it's a lot easier to just either use a helper method, or plain old html.

Cheers,


0
 

Author Comment

by:ARACK04
ID: 22689524
I'd love to use plain HTML - the problem is is I'm looping through a collection of objects, and if I'm using html, I would have to have two calls to the current object ie

<table>
<% @people.each do |p| %>
<tr><td>
<%= check_box_tag (p.id)
</td><td>
HOW DO I GET THE NEXT OBJECT?
</td></tr>
<%end%>
</table>
0
 

Author Comment

by:ARACK04
ID: 22692139
Yeah - I think the answer was there-  I just didn't see it - just add names - here's the original code fixed:

                  <%= cycle("<tr><td>", "<td>", :name => :c1)  %>
                  
                  <input type="checkbox" id=<%= @subjects[i].id %> name="SubsChecked[]" value=<%= @subjects[i].id %>
                  <%= "checked=checked" if params["SubsChecked"] != nil && params["SubsChecked"].index(@subjects[i].id.to_s) != nil %> />                        
                  <label for=<%= @subjects[i].id %>><%= @subjects[i].name %></label>

                  <%= cycle("</td>", "</td></tr>", :name => :c2)  %>
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Ruby on Rails 4 459
Help to install RubyGems and cucumber on window 2 316
return captures in array 5 261
git - conflict 5 224
Article by: narshlob
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between…
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question