Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running loops or multi-line code on Heroku Console

Heroku console doesn't run loops in my app (though they work on my local machine AND heroku permits individual actions to be taken).

@companies.each do |c|
SyntaxError: /home/heroku_rack/lib/console.rb:150: syntax error, unexpected $end
@companies.each do |c|
                      ^
/home/heroku_rack/lib/console.rb:140:in `eval'
/home/heroku_rack/lib/console.rb:140:in `_eval'
/home/heroku_rack/lib/console.rb:73:in `block in process_command'
/usr/ruby1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'

Do you know why these errors might be occurring?

like image 717
sscirrus Avatar asked Feb 20 '11 12:02

sscirrus


1 Answers

it's not an error - it's a feature of how Heroku let's you interact with your application via the heroku console command - whilst appearing like a full console it simply isn't. Each line is transmitted over http and evaluated when you press enter so you can't actually use multiline commands, this will work though;

User.all.each {|user| user.update_attributes(:active => true) }

if it can't be written on one line you'll need to use a rake task or such like

EDITED: To contain correct syntax

like image 165
John Beynon Avatar answered Oct 13 '22 00:10

John Beynon