title: Trouble using a 'before_filter' method and rendering partials
body: <p>I am using Ruby on Rails 3 and I am trying to understand the behavior of the <code>before_filter</code> method in a controller.</p>
  
  <p>In my controller I have</p>
  
  <pre><code>class UsersController &lt; ApplicationController
    before_filter :authorize
  
    def show
      ...
    end
  end
  </code></pre>
  
  <p>If I browse, for example, the page <code>http://&lt;my_web_site&gt;/user/1</code> (that loads the <code>users/show.html.erb</code> view file populated of data from the User with ID 1) the <code>before_filter</code> works as well. That is, the <code>authorize</code> method does what it must do.</p>
  
  <p><em>If I render the <code>users/show.html.erb</code> view file as a template for another controller (example: the PostsController) this way</em></p>
  
  <pre><code># This code is in the `post/show.html.erb` file
  &lt;%= render :template =&gt; "/users/show", :locals =&gt; { :user =&gt; @user } %&gt;
  </code></pre>
  
  <p><em>the <code>before_filter</code> doesn't work</em>. That is, the <code>authorize</code> method seams do not run.</p>
  
  <p><strong>Why?! There is a reason for that behavior or I am wrong somewhere?</strong></p>
  
  <hr>
  
  <p><strong>UPDATE</strong> (after the @brad comment)</p>
  
  <blockquote>
    <p>Are you rendering that view as a
    partial template from within the users
    controller? If not the before_filter
    won't apply</p>
  </blockquote>
  
  <p>If it is as @brad say in his comment, <strong>how can I make the <code>before_filter</code> to work rendering that view for another controller than UsersController?</strong></p>