title: How to override the 'as_json' or 'to_json' method in order to 'respond_to' without including specified information?
body: <p>I am using Ruby on Rails 3 and I would like to override (possibly in the model file) the <code>as_json</code> or <code>to_json</code> method in order to <code>respond_to</code> an HTTP request without including some information.</p>
  
  <p>In my Account <em>model</em> I have</p>
  
  <pre><code>def as_json(options = {})
    super(
      :except =&gt; [
        :password
      ]
    )
  end
  </code></pre>
  
  <p>In my controller I have</p>
  
  <pre><code>format.json {
    render :json =&gt; @account, :status =&gt; 200
  }
  </code></pre>
  
  <p>When I make a request, for example, to <code>/account/1.json</code> I have back also the password attributes that, for security reasons, I don't want. </p>
  
  <p>So, <strong>how can I prevent to include specified information?</strong></p>
  
  <hr>
  
  <p>I can do this and it works</p>
  
  <pre><code>format.json {
    render :json =&gt; @account.to_json(:except =&gt; [:password]), :status =&gt; 200
  }
  </code></pre>
  
  <p>but it I need to <em>refactor</em>.</p>