Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an exit in ruby?

I use php and there is a handy exit; that will stop the execution of the page and let me view the page thus far and then lets me view the debugging that i need ..anything like that in ruby on rails

like image 775
Matt Elhotiby Avatar asked Jan 22 '23 07:01

Matt Elhotiby


2 Answers

The best method for debugging in rails is to start your server with debugging enabled ruby script/server --debugger (this requires the ruby-debug gem) gem install ruby-debug

You can then put <% debugger %> in your views, controllers or wherever you like (obviously omit the erb tags if outside of a view). the terminal you have the server running in will then show you a breakpoint debugger help from the prompt there will tell you more.

like image 170
Jeremy Avatar answered Jan 30 '23 00:01

Jeremy


You can do raise an exception in your code which stops the current method and prints the exception. Great for debugging.

For example raise @variable.inspect. Also calling the inspect method will show you a lot of information about your variable. Also you can use this in your views controllers models helpers if you are using rails.

In your view:

<%= raise @variable.inspect%>
like image 20
dombesz Avatar answered Jan 30 '23 02:01

dombesz