我使用的設計和devise_invitable爲什麼設計
gem 'devise', '>= 2.0.0'
gem 'devise_invitable', '~> 1.0.0'
invitable不發送一些電子郵件和我在網站的管理員部分的鏈接自動發送邀請電子郵件給用戶
= link_to 'Send Invitation', invite_user_path(@user), :remote => true, :title => "Sends an email directly to the user"
def invite
@user = User.find(params[:id])
User.invite!(:email => @user.email)
flash.now[:success] = "Invitation email has been sent"
respond_to do |format|
format.js
end
end
這將發送電子郵件給用戶誰已經在數據庫user.invitation_token不爲NULL,但跳過發送電子郵件給其他用戶....這是爲什麼,我該如何解決這個問題。同樣在devise_invitable的文檔中,這是他們說呼叫邀請的方式!
User.invite!(:email => "[email protected]", :name => "John Doe")
但是當我做,他們說我不能大規模分配屬性名稱
任何幫助,將不勝感激
我注意到,如果在用戶invitation_token場什麼的電子郵件會了,但如何創建,最初
UPDATE ...這裏是我的整個用戶模型
class User < ActiveRecord::Base
delegate :can?, :cannot?, :to => :ability
has_many :roles, :through => :role_users
has_many :role_users
has_many :notifications, :through => :subscriptions
has_many :subscriptions
has_many :companies, :through => :positions
has_many :positions
has_many :notification_histories
has_many :sites, :through => :site_users
has_many :site_users
scope :admins, joins(:roles).where("roles.name = 'SuperAdmin' or roles.name = 'SubAdmin'")
scope :regular, joins(:companies).where('positions.regular_user = 1').group('users.id')
scope :employee, joins(:companies).where('positions.regular_user = 0').group('users.id')
scope :current, :conditions => { :active => true }, :order => 'LOWER(first_name), LOWER(last_name) ASC'
default_scope :order => 'LOWER(first_name) ASC'
has_many :feedbacks do
def for_playlist(id)
find_or_create_by_playlist_id(id)
end
end
def name
"#{self.first_name} #{self.last_name}"
end
has_many :ratings, :through => :feedbacks do
def for_playlist(id)
where('feedbacks.playlist_id = ?', id)
end
end
Role::TYPES.each do |role|
define_method(role + '?') do
self.has_role?(role)
end
end
def has_role?(role_name)
role_name = role_name.name if role_name.is_a?(Role)
self.roles.where(:name => role_name.to_s).exists?
end
accepts_nested_attributes_for :roles, :notifications, :allow_destroy => true
def company
self.companies.first
end
def site
self.sites.first
end
validates :first_name, :presence => true
validates :last_name, :presence => true
validates :email, :presence => true
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create, :if => :email_present?
validates_uniqueness_of :email
validates_format_of :phone_number, :with => /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/, :allow_nil => true
validates_format_of :password,
:with => /^.*(?=.{6,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d\W]).*$/,
:message => "must be at least 6 characters, have one number and one capital letter",
:if => Proc.new { |user| !user.password.blank? }
before_validation :clear_empty_attrs
before_validation :clean_data
# Include default devise modules
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :invitable
# Setup accessible (or protected) attributes for devise support
attr_accessible :email, :password, :password_confirmation, :remember_me, :active,
:company_id, :first_name, :last_name, :phone_number, :role_ids, :notification_ids, :name
def role?(role)
return !!self.roles.find_by_name(role.to_s.camelize)
end
def ability
@ability ||= Ability.new(self)
end
def name
"#{first_name} #{last_name}"
end
def list_companies
companies.map(&:name).try(:join, ", ").try(:titlecase)
end
def email_present?
!self.email.blank?
end
protected
def clear_empty_attrs
@attributes.each do |key,value|
self[key] = nil if value.blank?
end
end
def clean_data
self.email.downcase! unless self.email.nil?
end
end
是:attr_accessible在您的用戶模式:名下的上市? 'attr_accessible:name,:email' –
更好的問題是,您可以輸出您的用戶模型嗎? –
確定一秒...... – Trace