Difference between p in a rails view and puts
I am a newbie in Rails. I created a controller and a action. In the corresponding view I used <%= puts "asd" %> once and <%= p "asd" %> the other time.
In case id puts it shows on the console and in case of p it is rendered as HTML. What is the possible reason?
puts calls the method to_s p calls the method inspect
class Foo def to_s "In #to_s" end def inspect "In #inspect" def def
Semantically, to_s is meant to output the representation of the object to the user, and inspect to hint about the internal properties of the object (kinda like python's repr), but that's just a convention.
If you want to inspect something in your HTML use <%= debug "something" %>