Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Add paywall functionality to app

Rails • Asked by Stan Smith

I would like to offer people x views of certain pages then prompt them to pay for access.
I was looking ot use this gem acts_as_paywall -
but wanted to know if there was an easier way to do this.


Hi Stan, if you're looking for something simple, I'd recommend just creating a session and using that session as a counter. The following is a pure Ruby implmentation. You'll want to make some adjustments for your Rails app. I haven't tested it within Rails yet but I think you'll get the point.

# Rails has a sessions object that you can use. the next line creates an object to represent it.
session = {}

# You typically have your content in a database and can pull it out as an object. The following will represent that object.
content = {}

# The following represents the values of your content.
content[:title] = 'Title of Content'
content[:content] = 'Display content'

# Create your pay wall session counter
session[:pay_wall] ||= 1

# Run your conditional to check the counter
if session[:pay_wall] >= 5
    puts 'Add Pay Wall code here'
elsif session[:pay_wall] >= 1
    session[:pay_wall] += 1
    puts content[:content]
    session[:pay_wall] = 1
    puts content[:content]

# Test the value of your session
puts session[:pay_wall]

Resources you may find interesting on the topic of sessions:

Thanks John for the thorough answer. I'm going to have a go at rolling this from scratch.

You're welcome! Good luck! :)

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 29,763+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.