On Nov 26, 2007 4:55 PM, Joshua Muheim
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
>
> Hi all
>
> I''m developing a plugin that looks like this so far:
>
> module ActsAsAuthenticated
> def self.included(base)
> base.extend(ClassMethods)
> end
>
> module ClassMethods
> def acts_as_authenticated(options = {})
> options = {
> :uid => :name
> }.merge(options)
>
> include(InstanceMethods)
>
> def authenticate(name, password)
> user = send("find_by_#{options[:uid]}".to_sym, name)
> if user
> if user.hashed_password != encrypted_password(password,
> user.password_salt)
> user = nil
> end
> end
> user
> end
> end
> end
> end
>
> The important line is
>
> user = send("find_by_#{options[:uid]}".to_sym, name)
>
> because I want the user of my plugin to be able to pass an optional
> option[:uid] to the plugin. But sadly, I get the following error:
>
> undefined local variable or method `options'' for Member:Class
>
> Why that? How can I achieve what I want?
>
> Thanks
> Josh
First off, did you do any research into the name and funcionality? Because
this already exists:
http://svn.techno-weenie.net/projects/plugins/acts_as_authenticated/
As for your code, you''ve got nested methods going on here, unless
there''s
code you kept out of the picture. Otherwise, options is a local variable to
the class method. You need to set a class method (preferrably with
write_inheritable_attribute) to use it later.
Jason
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---