views:

189

answers:

9

It's quite common in sites- you have a "demo" version with a guest account full of data/posts/comments that you can play with, and all the data is reset every few hours so users wont spam the demo site.

I thought to have another rails environment, "mysite_demo" and use a cron job to call rake to reset it's database every X hours, and populate the seed data.

Then it hit me that all over my app I'll have to check if I'm running in "demo-mode": For example, if the demo site has a login/register page too, a user might register, insert some data and wonder why his account is deleted after he logged in again.. so demosite shouldn't have a register option at all.

So I thought I'll make a "demo" branch of the code.. with the difference and just merge changes as I go... sounds like an overkill.

ideas?

A: 

If the demo version is running from its own database, how is it any different from the real thing? The demo site is just an instance of your product.

Just clean up the DB and redeploy the demo as needed. Is it just this simple or am I missing something?

basszero
some functionality is missing from the demo site, like registering a new user.. so as I wrote, cant just deploy as is, need to make it's own branch or have the code check if it's running production or demo. not sure if either options is good, hence the question :)
amikazmi
A: 

Then it hit me that all over my app I'll have to check if I'm running in "demo-mode" (e.g, you cant register a new user in the demo) and make the site behave accordingly.

If the site is in demo, why does it matter what the users do? Anything they do will be wiped in a few hours, so they won't be able to actually do work with it.

It sounds like you are trying to handicap the site so they will pay. I don't know what your site does, but if its a host based service(web page that stores & display information) then the limited life span of the data should deter squatters.

If you website does something that can be used elsewhere, then I can see limiting it. An example might be a service that transforms media formats, or writes resumes. If the user can do something useful in the 2 hour window and walk away with it, then you might consider branching.

Tilendor
no, not to handicap- the only thing I though about is that a user entering the demo will see a "register" option, will in fact register, and then wonder where all his data go after a hour.. so I wanted to disable the registering accounts in the demo, just let them have a guest account with all the data to play with
amikazmi
A: 

Why not allow the user to make an account even if it is deleted in an hour?
That allows them to see how the registration process of the script works for at least an hour, maybe give a message on the signup page that the account is only valid for an hour.

Just my thoughts

jasondavis
It's an option, but then again I'll have to insert a change to the signup page to show the message.. so it's the same problem :)
amikazmi
A: 

Is there any other functionality that is different in the demo version than the production environment? If it is just an issue of making the user register, you could just create a registered demo account in production, and give out the user name/password for people. Although this may not be an option depending on other business requirements.

Ryan M
the demo should have the exact same functionality, just seeded with data so the user wont have to create it all to see how the site looks "full".
amikazmi
I think it's a bit risky to run tasks on the production env that wipe out alot of data.. a different db is safer. also, less data pollution
amikazmi
A: 

If you are willing to use Authlogic you can take a look at this, then every X hours you can look through the database for users that start with anonymous_ and delete records that are associated with them.

Garrett
as I answered to ryan, it doesn't feel safe to mass create/delete data like that, more it it's in the legitimate user accounts.. I think it's just telling Murphy: "look here- a place when it all can go horribly wrong!" :)
amikazmi
A lot of people use this method, I am sure it was thought out before it was executed.
Garrett
A: 

In my application I started with a fixed demo user with an account that resets every hour. Something about that model didn't quite sit right - if there were multiple users hitting the demo at the same time you could get into some weird concurrency issues. And what if a user is in the middle of a demo and your reset the demo account? What happens?

I don't know if this model works for you but I ended up creating a brand new user account with a demo flag set in the database - I also automatically log the user in. This way the user gets to play around for as long as they like and I don't have to worry about data getting deleted/changed while a user demos my app. I run a cron job every night that deletes users with the demo flag set that are older than 24 hours.

Andy Gaskell
A: 

Just make a separate demo site that works exactly like the production one, but the DB gets reset once an hour to clean example data. The only change you need to make is a banner across the top of every page that says its a demo. There are several ways to do it, (modify your site theme, or maybe use frames) but basically you should only have to change the code in one place, instead of throughout the site.

davr
A: 

You could setup a new environment demo on your database.yml, with read-only privileges for the User table, and an additional demo_database. Then place some checks on your code to see if your RAILS_ENV is on DEMO.

That way, you only need to work with the same codebase and just show whatever you feel like it.

Yaraher
A: 

You can deploy it as a separate app with its own database to a separate domain or subdomain and then check the domain to decide what options should be available. For instance if you put it on demo.example.com you would use:

if request.domain =~ /demo/

If you use Capistrano you can set it up to update both apps when you deploy so they are in sync.

Roger Ertesvag