inherited_resources and Mongoid

93 views
Skip to first unread message

doabit

unread,
Aug 9, 2010, 3:28:53 AM8/9/10
to Mongoid
i use inherited_resources and mongoid in my porject,but iwhen use
inherited_resources link that :
class PostsController < InheritedResources::Base
belongs_to :user,:finder => :find_by_name, :param => :user_name
en

show errors :undefined method `find_by_name'

does anybody know ,how to path this ?thank you @@

Cyril Mougel

unread,
Aug 9, 2010, 3:42:24 AM8/9/10
to mon...@googlegroups.com

In your User model add the method

def self.find_by_name(name)
  where(:name => name).first
end



--
Cyril Mougel
http://blog.shingara.fr

Vous souhaitez poser des questions sur Ruby ?
N'hésitez pas à aller sur http://questions.rubyfr.org/

doabit

unread,
Aug 9, 2010, 3:54:10 AM8/9/10
to Mongoid
that work ! thank you ,

On 8月9日, 下午3时42分, Cyril Mougel <cyril.mou...@gmail.com> wrote:
> On Mon, Aug 9, 2010 at 9:28 AM, doabit <doins...@gmail.com> wrote:
> >  i use inherited_resources and mongoid in my porject,but  iwhen use
> > inherited_resources link that :
> >  class PostsController < InheritedResources::Base
> >     belongs_to :user,:finder => :find_by_name, :param => :user_name
> >  en
>
> >  show errors :undefined method `find_by_name'
>
> >  does anybody know ,how to path this ?thank you @@
>
> In your User model add the method
>
> def self.find_by_name(name)
>   where(:name => name).first
> end
>
> --
> Cyril Mougelhttp://blog.shingara.fr

Durran Jordan

unread,
Aug 9, 2010, 10:57:11 AM8/9/10
to mon...@googlegroups.com
Yeah Mongoid does not have the dynamic finders that active record
does, so you'll have to watch out for those.
Reply all
Reply to author
Forward
0 new messages