rails - named scoped help
- by sameera207
Hi All,
I want to write a named scoped to get a record from its id.
Ex: I have a model called Event and its same as doing Event.find(id) (I dont want to use find inside my controller and I want my controller to use a named scoped (for future flexibility))
So I have written a named scoped
named_scope :from_id, lambda { |id| {:conditions = ['id= ?', id] } }
and I'm calling it from my controller like Event.from_id(id)
But my problems is it returns Event object array not only one object
Ex: if I want to get event name I have to write
event = Event.from_id(id)
event[0].name
instead I want to write
event = Event.from_id(id)
event.name
Am I doing something wrong here..
thanks in advance
cheers
sameera