Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I skip email validation with Authlogic in Rails?

I use Authlogic for authentication in my Rails project.

It provide default validation for email and login field.

But, I want to allow email to be null for join because my service is for mobile and it is difficult to insert email field in mobile device.

How can I skip email validation with Authlogic in Rails?

like image 521
Jaehyun Avatar asked Jan 22 '23 20:01

Jaehyun


2 Answers

class User < ActiveRecord::Base
  acts_as_authentic do |c|
    c.validate_email_field = false
  end
end
like image 158
Simone Carletti Avatar answered Jan 25 '23 09:01

Simone Carletti


I was digging for this one for awhile - extending on what jaehyun said - say you want to skip email validation in Authlogic on a conditional basis

  acts_as_authentic do |c|
    c.merge_validates_length_of_email_field_options({:unless => Proc.new { |user| user.has_no_email? }})
    c.merge_validates_format_of_email_field_options({:unless => Proc.new { |user| user.has_no_email? }})
  end      
like image 20
Nathan Bertram Avatar answered Jan 25 '23 09:01

Nathan Bertram