[url=http://github.com/brianjlandau/acts_as_inviteable_example_app]这里是一个邀请的demo[/url]
安装可以按照插件形式安装
生成相应代码
实际会生成:
这时应该跑升级数据库结构:
如果本身没有User的模块,需要代参数生成该模块
同时,默认的用户邀请数是每用户可以邀请5人,这个可以定制如下:
插件同时提供:
[quote]
On the Invite Model:
Validates necessary attributes on the Invitation, including email address format.
Makes sure an invite hasn't already been sent to the recipient_email by validating it's uniqueness.
Makes sure the recipient's email isn't already in the User's table.
Makes sure the user has at least one invite left to give.
Automatically decrements the User's invitation_limit when an invite they created is saved.
Automatically sends an email to the recipient after the Invitation is saved.
A named_scope called by_created_at
A named_scope called unaccepted which finds all the invites that don't have users with a match for their recipient_email.
Sets up ActiveRecord relationships for both the sender and the recipient.
Has a accepted? instance method to test if the invite has been accepted or not.
On the Inviteable Model (User):
Sets the invitation_limit on create
Requires that the user have a valid invitation_code attribute or have the invite_not_needed attribute set to true.
Automatically set the Users email address to the recipient_email field on the invite.
Has an ActiveRecord relationship for sent_invitations, invites sent by the user.
[/quote]
安装可以按照插件形式安装
script/plugin install git://github.com/vigetlabs/acts_as_inviteable.git
生成相应代码
script/generate invitations_for User
实际会生成:
map.resource :invitation, :only => [:new, :create]
map.signup '/signup/:invite_code', :controller => 'users', :action => 'new'
这时应该跑升级数据库结构:
rake db:migrate
如果本身没有User的模块,需要代参数生成该模块
script/generate invitations_for --create-user-model User
同时,默认的用户邀请数是每用户可以邀请5人,这个可以定制如下:
acts_as_inviteable :default_invitation_limit => 20
插件同时提供:
[quote]
On the Invite Model:
Validates necessary attributes on the Invitation, including email address format.
Makes sure an invite hasn't already been sent to the recipient_email by validating it's uniqueness.
Makes sure the recipient's email isn't already in the User's table.
Makes sure the user has at least one invite left to give.
Automatically decrements the User's invitation_limit when an invite they created is saved.
Automatically sends an email to the recipient after the Invitation is saved.
A named_scope called by_created_at
A named_scope called unaccepted which finds all the invites that don't have users with a match for their recipient_email.
Sets up ActiveRecord relationships for both the sender and the recipient.
Has a accepted? instance method to test if the invite has been accepted or not.
On the Inviteable Model (User):
Sets the invitation_limit on create
Requires that the user have a valid invitation_code attribute or have the invite_not_needed attribute set to true.
Automatically set the Users email address to the recipient_email field on the invite.
Has an ActiveRecord relationship for sent_invitations, invites sent by the user.
[/quote]