> But I don't want to send the content back to client, but would like to
> see it right in the console where I started sinatra (not in a separate
> file).
I usually do just something like
pp params
--
Mika Tuupola
http://www.appelsiini.net/
get '/' do
content_type :json
require ruby-debug/debugger
"#{params}"
end
Here's a nice intro post to ruby-debug: http://pivotallabs.com/users/chad/blog/articles/366-ruby-debug-in-30-seconds-we-don-t-need-no-stinkin-gui-
Best.
Mike
> --
> You received this message because you are subscribed to the Google Groups "sinatrarb" group.
> To post to this group, send email to sina...@googlegroups.com.
> To unsubscribe from this group, send email to sinatrarb+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sinatrarb?hl=en.
>
Keep in mind though that this depends on how you're hosting your app, and doesn't always work (e.g. with Passenger and Apache/Nginx).
Others have already mentioned ruby-debug, but I would also recommend some kind of logging system. There's quite a few gems out there that do this for you, but I tend to stick to the `Logger' class that comes with the standard library: http://rubydoc.info/docs/ruby-stdlib/1.9.2/Logger
Here's a simple program that demos its usage in a Sinatra program that should get you started:
require 'sinatra'
require 'logger'
configure do
# Create the log file if it doesn't exist,
# otherwise just start appending to it,
# preserving the previous content
log_file = File.open('my_app.log', 'a+')
# Don't buffer writes to this file. Recommended for development.
log_file.sync = true
logger = Logger.new(log_file)
# Log everything to the log file
logger.level = Logger::DEBUG
set :logger, logger
end
# Convenience method
def logger; settings.logger; end
get '/' do
logger.debug "params: #{params.inspect}"
"Hello, world!"
end
You can then do a `tail -f my_app.log` and see the logging output.
g, Markus