4 Replies - 5379 Views - Last Post: 27 December 2010 - 11:28 AM Rate Topic: -----

#1 german129   User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 43
  • Joined: 03-September 10

Rails: html tag id's from variables

Posted 16 December 2010 - 10:37 AM

This forum seems rather desolate compared to the others here but i hope i can find an answer to this question anyway. I would like to create the id portion of a <td> tag using a string variable in rails. In my program i have a table that will have a varying number of columns determined by a variable in the parameter file. I would like to be able to loop through each row labeling each column based on its column number as shown below. The problem is i do not know how to have the variable "item" read into the tag. Any solution or other suggestion on how to solve this problem would be appreciated.

<table>
  <tr>
    <%for item in 0..$gItems%>
      <td id="col" + item.to_s >
         <%= "col" + item.to_s %>
      </td>
    <%end%>
  </tr>
</table>



Is This A Good Question/Topic? 0
  • +

Replies To: Rails: html tag id's from variables

#2 girasquid   User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: Rails: html tag id's from variables

Posted 16 December 2010 - 11:49 AM

Assuming that your code sample is what you're looking for, and you're just having trouble with the string formatting, try this:
<table>
  <tr>
   <% for item in 0..$gItems %>
    <td id=<%= "col#{item}">
     <%= "col#{item}">
    </td>
   <% end %>
  </tr>
</table>


Was This Post Helpful? 0
  • +
  • -

#3 german129   User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 43
  • Joined: 03-September 10

Re: Rails: html tag id's from variables

Posted 16 December 2010 - 12:05 PM

works perfectly...thanks
Was This Post Helpful? 0
  • +
  • -

#4 MitkOK   User is offline

  • D.I.C Regular
  • member icon

Reputation: 32
  • View blog
  • Posts: 403
  • Joined: 09-August 07

Re: Rails: html tag id's from variables

Posted 25 December 2010 - 01:39 AM

Using for in rails view using range with global var is just wrong.
Was This Post Helpful? 0
  • +
  • -

#5 german129   User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 43
  • Joined: 03-September 10

Re: Rails: html tag id's from variables

Posted 27 December 2010 - 11:28 AM

View PostMitkOK, on 25 December 2010 - 12:39 AM, said:

Using for in rails view using range with global var is just wrong.


In that case, feel free to give me some ideas on how I can accomplish this without a global and without a db.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1