title: How to add errors to Rails model?
body: <p>I tried to add an exception in the <code>before_save</code> method in a rails model, but in the view, no error message exists. </p>
  
  <p>Model:</p>
  
  <pre><code>before_save do
      doing_some_stuff
      begin
        File.open('some_file', 'w+') do |file|
          if file.write(file_content)
            return true
          else
            return false
          end
        end
      rescue =&gt; e
        self.errors.add(:base, e.message) 
        return false
      end
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;%= @model.errors.any? %&gt;
  </code></pre>
  
  <p>This is always false.</p>
  
  <p>How do I add error messages to the model?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The problem was, I had a redirect after the update_attribute function instead of rendering the action again. Thx for help.</p>