title: How to customize action when matching item exists
body: <p>I am checking whether a book exists, and if so, render some action. I'd like this action to be a popup message or redirecting to another page.</p>
  <p>Here's the code in my model:</p>
  <pre class="lang-rb prettyprint-override"><code>def
      existing_book = Book.find_by('author LIKE ? AND name LIKE ?', &quot;#{self.author}&quot;, &quot;#{self.name}&quot;)
  
      if existing_book != nil
        errors.add(:name, message: &quot;This book may already exist.&quot;)
      end
  end
  </code></pre>
  <p>The problem is that besides <code>errors.add</code> to show the error text on the same screen, I can't get it to do popup message or redirect. <code>redirect_to</code> or such code that work in controller doesn't work in this model file. How can I do a popup message or redirect in this case?</p>
  <p>If that is impossible, how can I at least make the error message show more than one model? Above, there's only <code>:name</code>, but I'd like to show both name and author. Right now the error message shows as: &quot;Name This book may already exist.&quot;</p>
  <p>I'd really appreciate any help.</p>