cycle twice

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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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)

then just call it from the view as

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

ARACK04Author Commented:
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?
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.



Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ARACK04Author Commented:
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

<% @people.each do |p| %>
<%= check_box_tag (
ARACK04Author Commented:
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)  %>
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.