I've been wrestling with this a big, and I haven't found the solution
that feels *right* yet. This must be a common need, so I figured I'd
write the list.
On my site I let users start using the site, and creating personalized
stuff before actually formally "signing up". Which means I'm
attaching user data to a User model, before I've even gotten their
username and password. Then, if they choose to, they can sign up.
The trouble this causes is that Authlogic seems to expect that you
decide on your username/password validations at the class level, but I
really want to decide at the instance level. Basically I want to be
able to do this:
u = User.new
u.should be_valid
u.activate
u.should_not be_valid
u.update_attributes(:login => "erik", :password => "lalala")
u.should be_valid
Unfortunately, there doesn't seem to be a way to do this in Authlogic,
because it requires changing the configuration at the instance level,
rather than the class level.
I'm considering using single table inheritance, and having a
ProspectiveUser class with a different set of validations, but I tried
it before and it was a bit of a mess. Anyone have any suggestions?
-Erik
Search the google group for the keywords "gradual engagement" -- I have this same requirement for my site and came up with "a" solution. I'm sure there are other solutions but maybe that one will work for you or provide a starting point.
Kevin
> --
> You received this message because you are subscribed to the Google Groups "Authlogic" group.
> To post to this group, send email to auth...@googlegroups.com.
> To unsubscribe from this group, send email to authlogic+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/authlogic?hl=en.
>
Ah, "gradual engagement" is the magic incantation. :)
Thanks for the tip. But I tried using the conditionals
(c.validate_login_field = {:if => :active?}) and it still didn't
work. Here's a barebones test case that fails:
(running spec -c gradual_engagement_spec.rb should work without any
dependencies.)
Any ideas what I'm doing wrong?
Best,
Erik
class User < ActiveRecord::Base
validates_uniqueness_of :login, :if => :active?
validates_format_of :login, :with => Authlogic::Regex.login, :if
=> :active?
validates_uniqueness_of :email, :if => :active?
validates_format_of :email, :with => Authlogic::Regex.email, :if
=> :active?
validates_presence_of :password, :if => :active?
validates_length_of :password, :minimum => 3, :if => :active?
acts_as_authentic do |c|
c.validate_login_field = false
c.validate_password_field = false
c.validate_email_field = false
end
end
Oh well.
Erik