ruby on rails - devise invitable do not validate model -


first, excuse poor english, i'm french... it's tricky explain problem !

i have model user model in rails application:

class user < activerecord::base    attr_accessible :email, :gender, :lastname, :firstname      end 

and backuser model inherit user:

class backuser < user   # class backoffice user   devise :database_authenticatable,            :rememberable,            :trackable,            :lockable,            :invitable,            :confirmable,           :validatable,           :validate_on_invite => true    attr_accessible :password, :password_confirmation, :remember_me, :active, :role    validates :role, presence: true,                   inclusion: ["admin", "normal"]    validates :gender, presence: true    validates :firstname, presence: true    validates :lastname, presence: true     def admin?     self.role == 'admin'   end  end 

this second class should validate record before invite! but, when use console following:

u = backuser.new u.invite! 

"u" saved in database , invitation send blank email...

do know have do?

thans lot!

i'm sure you've found solution or workaround problem now, future users encounter same problem found pretty simple fix.

devise invitable's model configuration docs don't explain how implement :validate_on_invite, have set configuration option true - :validate_on_invite => true.

here's devise method looks in user model work correctly.

models/user.rb

# include default devise modules. others available are: # :confirmable, :lockable, :timeoutable , :omniauthable devise :invitable, :database_authenticatable, :registerable,        :recoverable, :rememberable, :trackable, :validatable, :validate_on_invite => true 

now when attempt submit invitation validating record validations i've set in user model before allowing invitation sent , user record created. looking @ docs, i'm guessing can enable setting in devise initializer, haven't tried going route.

*second possible option enable validation if needed

config/initializers/devise.rb

config.validate_on_invite = true 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -