title: How can I make named_scope in Rails return one value instead of an array?
body: <p>I want to write a <a href="http://rails.rubyonrails.org/classes/ActiveRecord/NamedScope/ClassMethods.html#M001684" rel="noreferrer">named scope</a> to get a record from its id. </p>
  
  <p>For example, I have a model called <code>Event</code>, and I want to simulate <code>Event.find(id)</code> with use of <code>named_scope</code> for future flexibility.</p>
  
  <p>I used this code in my model:</p>
  
  <pre><code>named_scope :from_id, lambda { |id| {:conditions =&gt; ['id= ?', id] } }
  </code></pre>
  
  <p>and I call it from my controller like <code>Event.from_id(id)</code>.  But my problem is that it returns an array of <code>Event</code> objects instead of just one object.</p>
  
  <p>Thus if I want to get event name, I have to write</p>
  
  <pre><code>event = Event.from_id(id)
  event[0].name
  </code></pre>
  
  <p>while what I want is </p>
  
  <pre><code>event = Event.from_id(id)
  event.name
  </code></pre>
  
  <p>Am I doing something wrong here?</p>