title: How to check if variable has error
body: <p>How to check if the variable has error in my controller before going to view.</p>
  
  <p>in my controller:</p>
  
  <pre><code>def index
      @sample_model = Model.all
      rescue =&gt; e
      flash.now[:alert] = e.message
  end
  </code></pre>
  
  <p>for example I have error <code>ActiveRecord::StatementInvalid: Mysql2::Error: Table 'models' doesn't exist: ...</code></p>
  
  <p>I want to check if first before going to view so I can show it my flash.</p>