在rails web app上为ruby创建试用期

Ton*_*ton 7 ruby web-applications ruby-on-rails

谁能告诉我在rails web应用程序上实现ruby 30试用期的最佳方式,就像37signals的Basecamp一样?

目前,我有一个用户注册页面,然后用户可以访问显示其产品/定价等当前信息的仪表板.

我希望用户能够注册并拥有完整的应用功能,然后在30天后过期.

谢谢

prz*_*adu 10

在x天试用期内创建Rails应用程序非常简单.

您希望为用户实施30天试用期,然后按照:

第1步:在application_controller.rb中创建这些方法

# application_controller.rb
class ApplicationController < ActionController::Base
 # make expire_on method available for all the controllers
 helper :all
 helper :remaining_days


 # find the remaining trial days for this user
 def remaining_days
  ((current_user.created_at + 30.days).to_date - Date.today).round
 end

 def trial_expired?
  # find current_user who is login. If you are using devise simply current_user will works
  # now that you have remaining_days, check whether trial period is already completed
  if remaining_days <= 0
     redirect_to expires_path
  end
 end
end
Run Code Online (Sandbox Code Playgroud)

第2步:在application.html.erb中显示剩余的试用天数

# application.html.erb
<html>
  <head></head>
  <body>
    <span style="color:red"> Your trial period will expire on <%= remaining_days %></span>  Days. Suscribe
  </body>
 </html>
Run Code Online (Sandbox Code Playgroud)

第3步:在每个控制器写入

class YourController < ApplicationController
 before_filter trial_expired?
end
Run Code Online (Sandbox Code Playgroud)

因此,如果试用期已过期,则无法访问您的页面,但会将用户重定向回错误消息页面.

现在创建一个expires控制器并在那里完成所有必需的功能.在expires>索引页面显示一些错误消息,如"您的试用期已完成,请订阅.................",无论您喜欢什么.

这适合我.


Sor*_*row 6

只需存储创建用户帐户的日期,以及布尔标志,无论帐户是否已付款.

或者使用日期字段,在该字段中设置用户可以访问完整功能的最后一天(并在注册时将此日期设置为注册后30天).

在任何情况下,请在登录时读取数据并根据它显示不同的内容.

那将是我的解决方案; 但我想可能会有更好更容易的东西.

编辑我普遍同意@Roland在他的回答中所说的话.布尔标志可以替换为有关帐户级别的信息,但是为此我会在字符串标签上使用整数(0表示试用,1表示基本,2个pro等).

您还可以通过在cron中安排rake任务,自动为在给定日期尚未支付的帐户执行某些操作.通过做某事我的意思是:无效,删除,将级别更改为基本等.