rails 插件 acts_as_inviteable 邀请机制简介

本文介绍了一个用户邀请插件的安装与配置方法。通过简单的命令即可完成安装,并可根据需求调整用户邀请限制。插件提供了丰富的功能,如验证电子邮件格式、确保未重复邀请等。
[url=http://github.com/brianjlandau/acts_as_inviteable_example_app]这里是一个邀请的demo[/url]

安装可以按照插件形式安装


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]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值