Search code examples
ruby-on-railsrubydebugging

var_dump and die like php, In ruby on rails (debug in ruby on rails)


This might be repeated question. But I can't display the object.

I'm new to ruby, tried to debug like var_dump and print_r then die in php

Here is my code.

@brand_id = Brand.maximum("brand_id")

I tried the following method

1 puts YAML::dump(@brand_id)
2 logger.debug { @brand_id.inspect }

Can anyone help me resolve it, pls?


Solution

  • Rails will only output views to the browser. Any other output is sent to STD_OUT on the server.

    Debugging from views is simple:

    <%= debug @brand %>
    

    But debugging from inside a controller or model requires you to either halt the execution with abort, which will output an error page:

    abort @brand.inspect
    

    Or you can write to the rails log with:

    logger.debug(@brand.inspect)
    

    You can read the log by using tail -f /logs/development.log from the your shell.