Within Ruby on Rails, what’s the best way to find out what data a variable has? For example, let’s say I have @customer, and I know that @customer will allow me to print @customer.name, @customer.address, and @customer.phone, but I don’t know what other data @customer allows in the specific view I’m working in. How can I find out what data @customer contains within my current view?
How can I find out what data I can access within a variable in Ruby on Rails from within my current view?
If you are going to ‘debug’ and use a view for it, you could use
debug @varorputs @var.inspect.But the best and cleaner way I have found is using the pry gem. Just
cdinto the variable and thenlsto show all the methods and attributes.