Create a trial period for a ruils ruils web application

can someone tell me the best way to implement 30 trial periods for ruby ​​on the rails web application, just like Basecamp from 37signals does?

Currently I have a user login page, which then gives the user access to a dashboard that displays current information about their products / prices, etc.

I would like users to be able to register and have the full functionality of the application, which expires in 30 days.

thanks

+6
source share
5 answers

Just save the creation date of the user account along with the boolean flag whether the account has been paid.

Or use the date field on which you set the last day when the user has access to full functionality (and during registration you will set 30 days from the date of registration for this date).

In any case, read the data when you log in and display other content on it.

That would be my decision; but I suppose something could be better and easier.

Edit I generally agree with what @Roland said in his answer. The boolean flag can be replaced by account level information, however, for this I would use an integer (0 means trial version, 1 basic version, 2 pro, etc.) above the string tag.

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

+6
source

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

You want to implement a 30-day trial period for your users, and then follow these steps:

step 1: create these methods in application_controller.rb, for example

# 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 days of judicial 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: write in each controller

 class YourController < ApplicationController before_filter trial_expired? end 

so if the trial version has already expired, it will not allow access to your page, but will redirect the user back to the error message page.

Now create one expires controller and perform all the necessary function. The expires> index page displays some error message like "Your trial period is completed, please subscribe .................", whatever you want.

This works for me.

+8
source

Why I would like to approach it is to set trial_started_at for the user and check it every time the user logs in, unless they have bought it.

0
source

What are Sorrow and Ant, but instead of logical use tag for users: Trial, Basic, Pro, etc.

0
source

As Sorrow says:

Use the "date" field in which you set the last day when the user has access to the full functionality> (and during registration you will set 30 days for this date from the date of registration).

I am only retelling to emphasize that this is the best option, and not storing the trial version when starting, the code for checking the first one: trial_expiry > Time.now , while the code for checking the started date of the samples should be more confusing, and it makes it difficult to conduct various length tests.

You can clear the expiration date when they buy an account, there is no need to check a separate field. Some kind of user level is still a good idea, but not needed for a trial system.

0
source

Source: https://habr.com/ru/post/890675/


All Articles