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.
77236cb3ef11b54bd21026de39e4050d?d=identicon&s=25 pixelmech (Guest)
on 2005-11-12 12: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/
317aad7f9f0b69a440faca74bbe22b20?d=identicon&s=25 jakob (Guest)
on 2005-11-12 12: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")
77236cb3ef11b54bd21026de39e4050d?d=identicon&s=25 pixelmech (Guest)
on 2005-11-12 12:49
(Received via mailing list)
--- Jakob Skjerning <jakob@mentalized.net> 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/
C35fb25ec709dba77454797ffa0d9016?d=identicon&s=25 mtmusko (Guest)
on 2005-11-12 12: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...

On 11/8/05, Tom Dell'Aringa <pixelmech@yahoo.com> wrote:
>
> Do I have to declare logger somehow?
>
--
Frank Kim
http://meetingkoreans.com
http://betweengo.com
632a66b453075df1176d8a0c7e33cfc9?d=identicon&s=25 raf1hh (Guest)
on 2005-11-12 12: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.