Nehal Soni
unread,Dec 11, 2010, 10:33:52 AM12/11/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Devise
Hi,
I'm using Rails 2.3.8.
I have a user setup on devise, on signup they provide a username,
email and password and subdomain (i.e company name).
I wish to create many users for a given company, as long as the
username is unique. So multiple emails should be allowed.
When I try the above I get an "email is already taken" validation
error message. I removed the validatable module but an SQL Exception
is caught indicating that the email is not unique.
My quuestion is, can remove the email uniqueness validation, and just
ensure the company and username is unique for a given user.
class User < ActiveRecord::Base
belongs_to :company
devise :database_authenticatable, :recoverable,:rememberable, :trackable, :validatable, :authentication_keys
=> [:username, :company_id]
accepts_nested_attributes_for :company
validates_uniqueness_of :username
validates_presence_of :username
validates_associated :company
validates_format_of :username, :with => /^\w+$/i,
:message => "can only contain letters and numbers."
def self.find_for_authentication(conditions={})
conditions[:companies] = { :name =>
conditions.delete(:company_id) }
find(:first, :conditions => conditions, :include => :company)
end
end