11155
(-- --)
July 30, 2010, 12:40am
1
I'm trying to render a list of div's with ids "item1", "item2", "item3",
etc..
Trying to do it like this:
<% for i in 0...@items.size %>
<div id="item<%= i %>" >
.. blah blah ..
</div>
<% end %>
Pretty sure the syntax is wrong. I couldn't find the answer after
googling for a bit - perhaps I'm too new and dont know where to look.
Help please?
<% @items.each do |item| %>
<%= item.record-name %>
</div> <% end %>
I think it goes model.method action |table| tuple.relvar.
I took the logic from here
http://guides.rails.info/getting_started.html#rest
and applied the solution for post to your problem.
I’m a newbian refuge as well.
What is the problem that you see?
Colin
If you're specifically after "item1" rather than "item<item.id>", then
you can use "each_with_index":
<% @items.each_with_index do |item, index| %>
<div class="item<%= index+1 %>">
<%= item.record-name %>
</div>
<% end %>
11155
(-- --)
July 30, 2010, 3:16pm
5
I realized I just typed the quotes wrong. Sorry!
Though thanks for the replies, especially @angel and @Michael Pavling,
those are really helpful suggestions.