<p>What is the best way for me to determine a controller variable's value during execution?</p>

<p>For example, is there a way I can insert a break in the code, and cause the value of the variable to be output to the screen (or the log)?</p>

[{'answer_id': 60731, 'author': 'Jordi Bunster', 'author_id': 4272, 'author_profile': 'https://Stackoverflow.com/users/4272', 'pm_score': 5, 'selected': True, 'text': '<p>Yes. The easiest way is to raise the value as a string. Like so: <code>raise @foo.to_s</code></p>\n\n<p>Or, you can install the debugger (<code>gem install ruby-debug</code>), and then start the development server with the <code>--debugger</code> flag. Then, in your code, call the <code>debugger</code> instruction.</p>\n\n<p>Inside the debugger prompt, you have many commands, including <code>p</code> to print the value of a variable.</p>\n\n<p><strong>Update:</strong> here\'s <a href="http://bashdb.sourceforge.net/ruby-debug.html" rel="noreferrer">a bit more about ruby-debug</a>.</p>\n'}, {'answer_id': 60732, 'author': 'John Topley', 'author_id': 1450, 'author_profile': 'https://Stackoverflow.com/users/1450', 'pm_score': 3, 'selected': False, 'text': '<p>If you have a controller instance variable named <code>@foo</code>, then in your controller you can simply do something like:</p>\n\n<pre><code>logger.debug "@foo is: #{@foo}"\n</code></pre>\n\n<p>Additionally, you can output the value in your view template using:</p>\n\n<pre><code>&lt;%= debug @foo %&gt;\n</code></pre>\n'}, {'answer_id': 60737, 'author': 'Jaryl', 'author_id': 6291, 'author_profile': 'https://Stackoverflow.com/users/6291', 'pm_score': 3, 'selected': False, 'text': '<p>I prefer using the inspect method like so:</p>\n\n<pre><code>raise @foo.inspect\n</code></pre>\n\n<p>It has more information than to_s, like the attribute values.</p>\n'}, {'answer_id': 63453, 'author': 'squadette', 'author_id': 7754, 'author_profile': 'https://Stackoverflow.com/users/7754', 'pm_score': 2, 'selected': False, 'text': '<p>Summary from Jordi Bunster, John Topley, and Jaryl:</p>\n\n<p>I. Quick and dirty way: </p>\n\n<pre><code>raise @foo.inspect\n</code></pre>\n\n<p>in your controller.  Or</p>\n\n<pre><code>&lt;% raise @foo.inspect %&gt;\n</code></pre>\n\n<p>in your view.  </p>\n\n<p>II. Proper logging to you <code>development.log</code>:</p>\n\n<pre><code>logger.debug "@foo == #{@foo.inspect}"\n</code></pre>\n\n<p>III. <a href="http://bashdb.sourceforge.net/ruby-debug.html" rel="nofollow noreferrer">Full-fledged debugging</a>:</p>\n\n<p>Install the debugger (<code>gem install ruby-debug</code>), and then start the development server with the <code>--debugger</code> flag. Then, in your code, call the <code>debugger</code> instruction.</p>\n\n<p>Inside the debugger prompt, you have many commands, including <code>p</code> to print the value of a variable.</p>\n'}, {'answer_id': 63524, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>Raising an exception is the fastest way if you just need to look at a value, but it's worth the time to learn how to use the debugger properly. It's rare that you would only need to just see the value of a variable, you are likely trying to find a bug in your code, and that's what a debugger is for.</p>\n\n<p>Sending the info to the development log is slower than either of the other two options here so far if you learn how to use the debugger (who wants to read through log files). Use the logger for production, you are going to want to see what the value was when somebody calls you up and says everything is broken.</p>\n"}, {'answer_id': 71778, 'author': 'liangzan', 'author_id': 11927, 'author_profile': 'https://Stackoverflow.com/users/11927', 'pm_score': 0, 'selected': False, 'text': '<p>Well, I usually prefer the standard error output</p>\n\n<p>$stderr.print("whatever")</p>\n\n<p>Its simple and does the job.</p>\n'}, {'answer_id': 50114810, 'author': 'Daniel Garmoshka', 'author_id': 1751321, 'author_profile': 'https://Stackoverflow.com/users/1751321', 'pm_score': 0, 'selected': False, 'text': '<ol>\n<li>Add <a href="https://github.com/garmoshka-mo/pry-moves" rel="nofollow noreferrer">pry-moves</a> to Gemfile: <code>gem \'pry-moves\'</code></li>\n<li>Insert <code>binding.pry</code> where you want to stop</li>\n<li>Type variable\'s name to see its value</li>\n</ol>\n\n<hr>\n\n<p>Then continue by typing <code>c</code>, move to next line with <code>n</code> or perform other debugging actions until you will resolve the issue.</p>\n'}]
['https://Stackoverflow.com/questions/60720', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3764/']