I'm new to rails, but I'm trying to see the contents of a Ruby variable from my Rails View (html.haml file). I tried to print the variable in ruby (thinking that it would work in the terminal), but did not get any results. Any suggestions?
I know about the Rails Debugger, but would rather print my variables using validation instead.
You can use the method putsfrom your views to display information on the server console. You can use Haml from anywhere in your view:
puts
- puts @my_variable.inspect
:
= debug @object
.
If you need more detailed debugging messages, you can try something like this
view.haml = debug "my_variable_value: #{@my_variable}"
= debug "my_variable_value: #{@my_variable}"
controller.rb
def index @my_variable = true end