Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a trial period for ruby on rails web app

can anyone tell me the best way to implement a 30 trial period for a ruby on rails web app, much like the way Basecamp from 37signals does?

At the moment I have a user signin up page which then gives a user access to a dashboard displaying current information on their products/pricing etc.

I would like users to be able to signup and have full app functionality which then expires after 30 days.

Thanks

like image 659
Tony Staunton Avatar asked Jun 16 '11 12:06

Tony Staunton


2 Answers

Creating Rails application for x days trial period is pretty much easy.

You want to implement a 30 days trial period for your users then follow:

step 1: create these methods in application_controller.rb like

# 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

Step 2: Display the Remaining Trial Days in 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>

step 3: in every controller write

class YourController < ApplicationController
 before_filter trial_expired?
end

so that if trial is already expired it will not give access to your page, but redirect user back to error message page.

Now create one expires controller and do all the required function there. In expires > index page display some error message like "Your trial period is completed please subscribe................." whatever you like.

This works for me.

like image 159
przbadu Avatar answered Nov 16 '22 09:11

przbadu


Simply store the date when the user account was created, along with a boolean flag whether or not the account has been paid.

Or use a date field in which you set the last day the user has the access to the full functionality (and on registering you set this date to be 30 days from registration).

In any case, read the data upon logging in and display different content based on it.

That would be my solution; but I suppose there might be something better and easier.

Edit I generally agree with what @Roland said in his answer. The boolean flag can be replaced with an information about the level of the account, however for that I would use an integer (0 meaning trial, 1 basic, 2 pro, etc.) over a string tag.

You can also automatically do something to accounts that have not been paid at a given day by scheduling a rake task in cron. By do something to I mean things like: invalidate, delete, change level to basic, etc.

like image 23
Miki Avatar answered Nov 16 '22 09:11

Miki