# In the .rhtml or in the controller

**URL:** <https://www.ruby-forum.com/t/in-the-rhtml-or-in-the-controller/129362>\
**Category:** Ruby\
**Created:** [February 17, 2008, 5:15pm UTC](https://www.ruby-forum.com/t/in-the-rhtml-or-in-the-controller/129362 "2008-02-17T17:15:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![macaco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@macaco](https://www.ruby-forum.com/u/macaco)\
**Post date:** [February 17, 2008, 5:15pm UTC](https://www.ruby-forum.com/t/in-the-rhtml-or-in-the-controller/129362/1 "2008-02-17T17:15:13Z")

</div>

Hi list  
I’v been wondering how to make an ‘each’ or a loop or something so I  
don’t  
have to write this code N times:

Imagen 0
\<%= link\_to\_remote image\_tag("/generate/imagen/0"), :url =\> {:action=\> "generate", :id =\> 0}, :update =\> "show\_div" %\>
 \<%= draggable\_element :dragg0, :handle =\> "'handler0'" %\> 

Imagen 1
\<%= link\_to\_remote image\_tag("/generate/imagen/1"), :url =\> {:action=\> "generate", :id =\> 1}, :update =\> "show\_div" %\>
 \<%= draggable\_element :dragg1, :handle =\> "'handler1'" %\>
# the same for N images

As you can see, it’s just the same code but the Id of the image and a  
position. But If I put this code in the controller, I can’t create  
those  
\<%= %\> tags, they won’t be recognized. Or at least it didn’t for me.

Any idea, shall I make it in the controller? it’s there a way to do it  
in  
the .rhtml?

---

<div class="post-metadata">

**Author:** ![macaco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@macaco](https://www.ruby-forum.com/u/macaco)\
**Post date:** [February 20, 2008, 3:57am UTC](https://www.ruby-forum.com/t/in-the-rhtml-or-in-the-controller/129362/2 "2008-02-20T03:57:45Z")

</div>

I’ve come to this

```
<% 0.upto(7) { |x| %>
  <div id="dragg<%= x %>" class="green box"

```

style=“position:absolute;top:\<%= 190+((x / 4)\*195) %\>px;left:\<%= 55 + (x  
\*  
195) %\>px”\>

Imagen \<%= x  
%\>&nbsp;\<%= check\_box\_tag “cruzar”+x.to\_s%\>
\<%= link\_to\_remote  
image\_tag("/generate/imagen/"+x.to\_s), :url =\> {:action=\> “generate”,  
:id =\>  
x}, :update =\> “show\_div” %\>  
\<%= draggable\_element “dragg”+x.to\_s, :handle =\>  
“'handler”+x.to\_s+"’"  
%\>  
\<% } %\>

Someone out there might be needing this. 🙂 Just be careful with the use  
of  
\<%= x %\> and simply ‘x’ (without the quotes) or x.to\_s
