Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>How I broke it, how I fixed it, and how I learned my lesson</h2> <p>I figured out the problem while lying in bed this morning, and it boils down to "I did something stupid." (Doesn't it always?)</p> <h3>The smart part</h3> <p>First, the smart part: I followed <a href="http://pivotallabs.com/users/nick/blog/articles/272-access-control-permissions-in-rails" rel="nofollow noreferrer">some neat advice about setting up access control and permissions</a>. It gives you some great a great syntax for saying what's allowed, like this:</p> <pre><code>&lt;%= link_to 'Delete', @photo, :confirm =&gt; "Really delete this photo?", :method =&gt; :delete if current_user.can_delete?(@photo)%&gt; </code></pre> <p>(The <code>current_user</code> bit comes from the Restful-authentication plugin.)</p> <p>The author also shows how to handle the case where a user tries to type in a URL for which you haven't given them a link. It involves setting up a special exception class, which subclasses <code>StandardError</code>, and handling it with something like a <code>401.html</code> - access denied.</p> <h3>The stupid part</h3> <p>What I did that was stupid was <strong>I followed his example blindly.</strong> He shows this:</p> <pre><code>def rescue_action(e) case e when SecurityTransgression head :forbidden end end </code></pre> <p>...which handles the <code>SecurityTransgression</code> fine, but <strong>breaks the default error handling in Rails</strong>. (I'm sure the author knows this and dealt with it, but he didn't discuss it.)</p> <h3>The solution</h3> <p>The solution was to add two lines:</p> <pre><code>def rescue_action(e) case e when SecurityTransgression head :forbidden else super end end </code></pre> <p>The "else super" part says "if I haven't specified anything here, let the inherited <code>rescue_action</code> method handle it."</p> <p>Now I'm getting the correct stack trace for my original problem, and will proceed to troubleshoot it.</p> <p>The lesson: be careful when you mess with exception handling, and make sure the default case still works!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload