Forum: Ruby on Rails Using PUTS to send message to console

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.
pixelmech (Guest)
on 2005-11-12 13:49
(Received via mailing list)
Hi,

I'm having trouble with my card not working correctly (not adding to
quantity instead of adding
full new line item) so I figured I would output some messages to the
console to see what clause I
am in, so I tried this:

def add_product(product)
    item = @items.find {|i| i.product_id == product.id}
    if item
	puts "if clause"
      item.quantity += 1
    else
	puts "else clause"
      item = LineItem.for_product(product)
      @items << item
    end
    @total_price += product.price
	puts "end"
  end

but the puts messages are not showing up...is this not a technique that
will work? Is there some
other way I can write to the console?

Hopefully this is my last dumb question of the evening.

Tom


http://www.pixelmech.com/
jakob (Guest)
on 2005-11-12 13:49
(Received via mailing list)
Tom Dell'Aringa wrote:
> but the puts messages are not showing up...is this not a technique
> that will work? Is there some other way I can write to the console?

When runnign Webrick it should "work", ie display the output in the
Webrick console window. When running FastCGI I hear rumours it'll crash
the FastCGI handler. Undefined results outside of those two scenarios, I
guess.

A better way to go about it would probably be to add to your logfile:

logger.info("if clause")
pixelmech (Guest)
on 2005-11-12 13:49
(Received via mailing list)
--- Jakob S. <removed_email_address@domain.invalid> wrote:

> Tom Dell'Aringa wrote:
> > but the puts messages are not showing up...is this not a technique
> > that will work? Is there some other way I can write to the console?
>
> When runnign Webrick it should "work", ie display the output in the
> Webrick console window. When running FastCGI I hear rumours it'll crash
> the FastCGI handler. Undefined results outside of those two scenarios, I
> guess.

I'm not using FastCGI and am using Webrick.

> A better way to go about it would probably be to add to your logfile:
>
> logger.info("if clause")

Makes sense, but I got this error when trying it:

undefined local variable or method `logger' for #<Cart:0x385cd88
@total_price=0.0, @items=[]>

Do I have to declare logger somehow?

Tom


http://www.pixelmech.com/
mtmusko (Guest)
on 2005-11-12 13:49
(Received via mailing list)
If you are in a model or controller you access the logger via the
logger variable.
If you are in a view you access the logger via the @logger variable.

http://wiki.rubyonrails.com/rails/pages/HowtoAcces...
raf1hh (Guest)
on 2005-11-12 13:49
(Received via mailing list)
puts never worked for me with webrick. Try: warn 'blah blah' ....
This topic is locked and can not be replied to.