# Foreach item in column

**URL:** <https://www.ruby-forum.com/t/foreach-item-in-column/85354>\
**Category:** Rails\
**Created:** [March 22, 2006, 4:54pm UTC](https://www.ruby-forum.com/t/foreach-item-in-column/85354 "2006-03-22T16:54:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [March 22, 2006, 4:54pm UTC](https://www.ruby-forum.com/t/foreach-item-in-column/85354/1 "2006-03-22T16:54:11Z")

</div>

Hi there,

I have a database with phonenumbers, and I want to make a function  
that runs a command for each of these numbers, with the number as an  
argument

Something like this in Perl:  
system(“/bin/command $number”);

mysql\> select \* from numbers where list = “one”

±—±---------±---------±--------------------±----------+  
| id | number | name | email | list |  
±—±---------±---------±--------------------±----------+  
| 2 | 9341 | Martin | removed\_email\_address@domain.invalid | one  
±—±---------±---------±--------------------±----------+

It would be very helpful if anyone could give me some examples on how  
to achieve this! 🙂

I´ll be very grateful for all help I can get!

Best regards,  
Martin S.\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
Rails mailing list  
removed\_email\_address@domain.invalid  
[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

---

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [March 22, 2006, 5:15pm UTC](https://www.ruby-forum.com/t/foreach-item-in-column/85354/2 "2006-03-22T17:15:37Z")

</div>

> | 2 | 9341 | Martin | removed\_email\_address@domain.invalid | one  
> ±—±---------±---------±--------------------±----------+

Select the desired records in the controller. Then do a:

for person in @people  
system(/bin/command person.number)  
end

regards  
Claus

---

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [March 23, 2006, 11:57am UTC](https://www.ruby-forum.com/t/foreach-item-in-column/85354/3 "2006-03-23T11:57:07Z")

</div>

Hello,

On Mar 22, 2006, at 5:15 PM, Claus G. wrote:

> > | 2 | 9341 | Martin | removed\_email\_address@domain.invalid | one  
> > ±—±---------±---------±--------------------±----------+
> 
> Select the desired records in the controller. Then do a:
> 
> for person in @people  
> system(/bin/command person.number)  
> end

Thanks, Claus! But I didn´t quite get it to work

Here´s what I have done.

- index.rhtml:  
\<%= link\_to ‘Iterate over all the numbers’, { :action =\>  
‘iterate’, }, %\>

- numbers\_controller:

def iterate  
@people = Number.find(:all,  
:conditions =\> “list = ‘one’”)  
for person in @people  
system(“echo ‘person.number’ \> /tmp/outout”)  
end  
end

$ cat /tmp/outout  
person.number

How do I make it echo/print the variable, not just the name? I tried  
with and without ’ around person.number.

Best regards,  
Martin S.\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
Rails mailing list  
removed\_email\_address@domain.invalid  
[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

---

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [March 23, 2006, 12:28pm UTC](https://www.ruby-forum.com/t/foreach-item-in-column/85354/4 "2006-03-23T12:28:49Z")

</div>

try this  
system(“echo #{person.number} \> /tmp/outout”)

Gokhan  
[www.sylow.net](http://www.sylow.net)

---

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [March 23, 2006, 12:33pm UTC](https://www.ruby-forum.com/t/foreach-item-in-column/85354/5 "2006-03-23T12:33:13Z")

</div>

sorry, I though this is the whole posting!

☹

---

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [March 23, 2006, 12:32pm UTC](https://www.ruby-forum.com/t/foreach-item-in-column/85354/6 "2006-03-23T12:32:13Z")

</div>

with\_irony do  
wow! i am deeply impressed…  
end
