Forum: Ruby on Rails foreach item in column

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Martin S. (Guest)
on 2006-03-22 17:54
(Received via mailing list)
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
Claus G. (Guest)
on 2006-03-22 18:15
(Received via mailing list)
> |  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
Martin S. (Guest)
on 2006-03-23 12:57
(Received via mailing list)
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
Gokhan A. (Guest)
on 2006-03-23 13:28
try this
system("echo #{person.number}  > /tmp/outout")

Gokhan
www.sylow.net
Peter E. (Guest)
on 2006-03-23 13:32
(Received via mailing list)
with_irony do
  wow! i am deeply impressed...
end
Peter E. (Guest)
on 2006-03-23 13:33
(Received via mailing list)
sorry, I though this is the whole posting!

:-(
This topic is locked and can not be replied to.