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?
To dump information about a variable, use the var dump() function. To make the output of the var_dump() method more legible, wrap it with a pre tag. The die() function immediately exits the script. To dump and die, use the var dump() and death() functions together.
Controllers use @user to ensure a user object can be shared by different methods (and views) in the controller instance. It may be that during a test a controller instance is initialized and both @user instance variables happen to be created but they are not the same variable.
This function displays structured information about one or more expressions that includes its type and value. Arrays and objects are explored recursively with values indented to show structure.
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.
The Rails equivalent of php's var_dump
would be debug
:
<%= debug @brand_id %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With