Reputation: 1052
I'm quite a rails beginner, but I am trying to see the contents of a Ruby variable from within my Rails View (html.haml file). I tried to print out the variable in ruby (thinking it would turn out in the terminal), but didn't get any results. Any suggestions?
I know about the Rails Debugger, but would rather prefer printing out my variables using inspect instead.
Upvotes: 5
Views: 11630
Reputation: 8035
In case of requiring more detailed debug messages you could try something like this
view.haml
= debug "my_variable_value: #{@my_variable}"
controller.rb
def index
@my_variable = true
end
Upvotes: 0
Reputation: 1931
You can use:
= debug @object
It's going to print and highlight the variable in the view.
Upvotes: 5
Reputation:
You can use the puts
method from within your views to output information to your server console. You should be able to do the following using Haml from anywhere in your view:
- puts @my_variable.inspect
Upvotes: 6