/rails-prelaunch-signup

An example Rails 3.2 app for a web startup prelaunch site.

Primary LanguageRuby

Rails App for a Startup Prelaunch Signup Site Rails App for a Startup Prelaunch Signup Site

Rails 3.2 example application for a “beta launching soon” startup prelaunch signup site.

There’s a detailed tutorial to show how it is built.

Plus you can generate the complete app in about a minute using an application template.

Rails Application for a Startup Prelaunch Signup Site

Sites Using the App

If you deploy a site using this example, please message Daniel Kehoe so we can let others know.

Site Author
XPlaygrounds.com Michael Gajda

Read an interview with Michael Gajda about how he used the project to launch his startup site.

Notable Forks

Alternative version Author
rails-prelaunch-signup-1click single-click email submit (no modal) Chad Kruse

Follow on Twitter Follow on Twitter

Follow the project on Twitter: @rails_apps. Please tweet some praise if you like what you’ve found.

Introduction

The initial app for a typical web startup announces the founders’ plans and encourages visitors to enter an email address for future notification of the site launch. It’s not difficult to build such an app in Rails.

But why build it yourself if others have already done so? This project aims to:

  • eliminate effort spent building an application that meets a common need;
  • offer code that is already implemented and tested by a large community;
  • provide a well-thought-out app containing most of the features you’ll need.

By using code from this project, you’ll be able to:

  • direct your attention to the design and product offer for your prelaunch site;
  • get started faster building the ultimate application for your business.

The tutorial can help founders who are new to Ruby on Rails to learn how to build a real-world Rails web application.

What Is Implemented — and What Is Not

This is a complete and fully functional application.

For the user:

  • an offer with a “request invite” button
  • a “request invitation” form in a modal window
  • “Thank you” acknowledgement includes social sharing buttons (Twitter, Facebook, Google+)
  • visitor receives an email acknowledging their request
  • visitor’s request for an invitation creates an “unconfirmed” account
  • a welcome email when a user is invited by a site administrator
  • a link in the welcome email confirms the user’s account and sets a password

For the site owner:

  • administrative dashboard page
  • list of all visitors who have requested invitations
  • time-series chart of invitation requests over time
  • site owner can send individual invitations
  • “bulk invitation” feature to send 50, 100, or more invitations
  • see status for any user: “uninvited”, “confirmed”, “last visit”

Implementation details:

  • Twitter Bootstrap
  • modal window for invitation requests updated by AJAX
  • Javascript updates the modal window for any form submission errors
  • uses an email service provider for transactional email
  • captures visitor email addresses for a MailChimp mailing list

Tutorial shows how to:

  • write user stories
  • manage a software development process using behavior-driven development (BDD)
  • prepare a specification using Cucumber scenarios
  • create acceptance tests using Cucumber step definitions (with Capybara)
  • use Devise for user management and authentication
  • use CanCan for role-based authorization
  • keep account passwords secret using Unix environment variables
  • use git and GitHub for source control
  • deploy using Heroku

Unimplemented

  • queuing (asynchronous processing) for transactional email and MailChimp list capture
  • caching
  • A/B testing of offers
  • advanced analytics
  • “about” and “contact” pages
  • Google analytics

If you add features or improve the implementation, please consider contributing by submitting an issue or pull request from your fork.

Alternatives

This is an application for Rails developers who wish to deploy their own app. It is a good stepping stone to building a more complex application for your startup. You’ll own your own code and can customize to your needs.

If you do not want to build an application, or you are not a Rails developer, you may wish to consider alternatives.

Hosted Services

LaunchRock – “set up a social launching-soon page in minutes”

KickoffLabs – “viral landing pages you’ll love in 60 seconds”

Prefinery – “complete beta management platform that encourages social sharing”

Unbounce – “create, publish & A/B test landing pages”

WordPress Themes

WordPress themes are a popular way to stage a startup prelaunch page.

Launch Effect – “a WordPress theme for viral launches”

Similar Projects

You can find other projects on GitHub that offer similar functionality.

Author Project Description
codelitt launchpage-rails Signup for two different types of users
johngrimes t-minus Instant prelaunch page for your Rails 3 app
renderedtext coming-soon Sinatra app to show a pre-launch page and collect emails
hashrocket coming-soon Sinatra app to register email addresses
jbeyers django-prelaunch Django app to gather email addresses with a referral mechanism

Found others? Please create an issue with your suggestion or email the author.

Articles and Discussion

Here are some articles that describe the purpose and options for a startup prelaunch page:

Have other suggestions? Please create an issue with your suggestion or email the author.

RailsApps Examples and Tutorials

This is one in a series of Rails example apps and tutorials from the RailsApps Project.

This application is based on two of the RailsApps example apps:

The first example shows how to set up Devise for user authentication. It also shows how to set up the app to use RSpec and Cucumber for testing.

The second example shows how to set up Devise and add CanCan to manage access to administrative pages. It also shows how to set up Twitter Bootstrap as a front-end framework for CSS styling.

You can use this example without studying these example applications; if you find you are lost, it may be helpful to look at the two simpler examples.

If you want to use the MongoDB datastore instead of ActiveRecord and a SQL database, look at rails3-mongoid-devise example.

Tutorial

A complete walkthrough tutorial is available on the GitHub wiki:

The tutorial documents each step to follow to create the application. Every step is documented concisely, so a complete beginner can create this application without any additional knowledge. However, no explanation is offered for any of the steps, so if you are a beginner, you’re advised to look for an introduction to Rails elsewhere. See a list of recommended resources for Rails.

If you simply wish to modify the application for your own project, you can generate the application and set it up as described below, without following the tutorial.

Dependencies

Before generating your application, you will need:

  • The Ruby language (version 1.9.3)
  • Rails 3.2

See Installing Rails 3.2 for detailed instructions and advice.

Accounts You May Need

Before you start, you may need to set up accounts for hosting and email.

Hosting

For easy deployment, use a “platform as a service” provider such as:

Instructions are provided for deployment to Heroku.

Transactional Email

For simple testing of email, it’s easy to use Gmail to send email messages from the application. For deployment, when the application must send dozens or thousands of acknowledgments or invitations, you will need a hosted SMTP relay service (also known as an ESP or “email service provider”). We provide instructions for Mandrill by MailChimp. The Mandrill transactional email service integrates well with the MailChimp email list manager service. Plus, you can send up to 12,000 emails/month from the service for free.

Sign up for a MailChimp account to get started. After you’ve created your MailChimp account, see the instructions to Use Mandrill with MailChimp. Then get the Access Information (your SMTP username and password, which is an API key).

Mailing List

In addition to sending transactional email messages, you likely will want to send newsletters or announcements to your entire mailing list. The tutorial shows how to add visitors who request an invitation to a MailChimp list. MailChimp allows you to send up to 12,000 emails/month to list of 2000 or fewer subscribers for free. After you sign up for a MailChimp account, get your API key. Look under “Account” for “API Keys and Authorized Apps.” Note that the Mandrill API key (which you get on the mandrill.com site) is different from the MailChimp API key (which you get on the mailchimp.com site).

Getting the Application

You have several options for getting the code.

Fork, Clone, or Generate?

Fork: If you’d like to add features (or bug fixes) to improve the app for others to use as a prelaunch signup site, you can fork the GitHub repo and make pull requests. Your code contributions are welcome!

Clone or Download: If you want to copy and customize the app with changes that are only useful for your own project, you can clone the GitHub repo or download a zip file. You’ll need to search-and-replace the project name throughout the application. You probably should generate the app instead (see below).

Generate: If you want to use the project as a starter app for your customized application, use the application template to generate a new version of the example app. You’ll be able to give it your project name when you generate the app.

Clone the Repository

If you simply wish to examine the example code, you can download the code (“clone the repository”) with the command:

$ git clone git://github.com/RailsApps/rails-prelaunch-signup.git

The source code is managed with Git (a version control system). You’ll need Git on your machine (install it from http://git-scm.com/).

As an alternative, you can download a zip file.

Using the Ready-Made Application Template

You can use an application template to generate a new version of the example app. You’ll find an application template for this app in the Rails Application Templates repository.

You’ll be able to give it your own project name when you generate the app. Generating the application allows you to choose from several options.

Use the command:

$ rails new rails-prelaunch-signup -m https://raw.github.com/RailsApps/rails3-application-templates/master/rails-prelaunch-signup-template.rb -T

Use the -T flag to skip Test::Unit files.

The $ character indicates a shell prompt; don’t include it when you run the command.

This creates a new Rails app named rails-prelaunch-signup on your computer. You can use a different name if you wish.

The application template will ask you for your preferences.

 question  Git branch for the prelaunch app?
       1)  wip (work-in-progress)
       2)  master
       3)  prelaunch
       4)  staging
 question  Git branch for the main app?
       1)  None
       2)  wip (work-in-progress)
       3)  edge
 question  Web server for development?
       1)  WEBrick (default)
       2)  Thin
       3)  Unicorn
       4)  Puma
 question  Web server for production?
       1)  Same as development
       2)  Thin
       3)  Unicorn
       4)  Puma
 question  Template engine?
       1)  ERB
       2)  Haml
       3)  Slim
   extras  Set a robots.txt file to ban spiders? (y/n)
   extras  Add 'therubyracer' JavaScript runtime (for Linux users without node.js)? (y/n)
   extras  Create a project-specific rvm gemset and .rvmrc? (y/n)
   extras  Create a GitHub repository? (y/n)

Git Branches

The application template will create Git branches for you. This allows you to maintain two versions of the application: one for immdediate deployment as a prelaunch app; and another version that you can use for ongoing development. I recommend deploying the prelaunch app in the “master” branch. Work on your ultimate application in a “wip” branch.

Web Servers

Use the default WEBrick server for convenience. If you plan to deploy to Heroku, select “thin” as your production webserver.

Template Engine

Choose “ERB” if you wish to duplicate the tutorial exactly.

Other Choices

Don’t set a robots.txt file to ban spiders if you want your new site to appear in Google search results.

The ‘therubyracer’ JavaScript runtime is for Linux users without node.js (see Installing Rails).

It is a good idea to use rvm, the Ruby Version Manager (see Installing Rails).

If you choose to create a GitHub repository, the application template will prompt you for a username and password.

Replace the READMEs

Please edit the README files to add a description of the app and your contact info. Changing the README is important if your app will be publicly visible on GitHub. Otherwise, people will think I am the author of your app (though please leave an acknowledgment and a link to the RailsApps project if you like).

Install the Required Gems

Install the required gems on your computer:

$ bundle install

You can check which gems are installed on your computer with:

$ gem list --local

Keep in mind that you have installed these gems locally. When you deploy the app to another server, the same gems (and versions) must be available.

Set Up Configuration for Devise

This app uses Devise for user management and authentication.

You can modify the configuration file for Devise if you want to use something other than the defaults:

config/initializers/devise.rb

Configure Email

You must configure the app for your email account so your application can send email messages, for example, to acknowledge invitation requests or send welcome messages.

The starter app script sets up a default email configuration. You must add details about your email account.

Configure ActionMailer

ActionMailer is configured for development in the config/environments/development.rb file:

# ActionMailer Config
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
# change to true to allow email to be sent during development
config.action_mailer.perform_deliveries = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"

ActionMailer is configured for production in the config/environments/production.rb file:

config.action_mailer.default_url_options = { :host => 'example.com' }
# ActionMailer Config
# Setup for production - deliveries, no errors raised
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"

ActionMailer is configured for testing in the config/environments/test.rb file:

# ActionMailer Config
config.action_mailer.default_url_options = { :host => 'example.com' }

This will set the example application to deliver email in production. Email messages are visible in the log file so there is no need to send email in development. The configuration above will raise delivery errors in development but not in production.

In development, config.action_mailer.default_url_options is set for a host at localhost:3000 which will enable links in Devise confirmation email messages to work properly during development.

For testing, config.action_mailer.default_url_options is set for a host at example.com. Any value allows tests to run.

For production, you’ll need to change the config.action_mailer.default_url_options host option from example.com to your own domain.

Use a Gmail account

Use Gmail for experimenting, if you want to keep things simple.

You’ll need to modify the files config/environments/development.rb and config/environments/production.rb:

config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: "example.com",
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: ENV["GMAIL_USERNAME"],
  password: ENV["GMAIL_PASSWORD"]
}

You can replace ENV["GMAIL_USERNAME"] and ENV["GMAIL_PASSWORD"] with your Gmail username and password. However, committing the file to a public GitHub repository will expose your secret password.

Use a Mandrill account

Use an SMTP relay service such as Mandrill if you want to increase deliverability for email messages from your app.

You’ll need to modify the files config/environments/development.rb and config/environments/production.rb:

config.action_mailer.smtp_settings = {
  :address   => "smtp.mandrillapp.com",
  :port      => 25,
  :user_name => ENV["MANDRILL_USERNAME"],
  :password  => ENV["MANDRILL_API_KEY"]
}

Note that the password will be your Mandrill API key.

You can replace ENV["MANDRILL_USERNAME"] and ENV["MANDRILL_API_KEY"] with your Mandrill username and API key. However, committing the file to a public GitHub repository will expose your secret API key.

Keep Email Account Passwords Secret

If you’re familiar with setting Unix environment variables, it’s advisable to leave config.action_mailer.smtp_settings unchanged and set your environment variables in the file that is read when starting an interactive shell (the ~/.bashrc file for the bash shell). This will keep the password out of your repository.

Are you using a bash shell? Use echo $SHELL to find out. For a bash shell, edit the ~/.bashrc file and add (for Gmail):

export GMAIL_USERNAME="myname@gmail.com"
export GMAIL_PASSWORD="secret"

or for Mandrill:

export MANDRILL_USERNAME="myname"
export MANDRILL_API_KEY="secret"

If you are using MailChimp for managing a mailing list, add your MailChimp API key:

export MAILCHIMP_API_KEY="secret"

After you deploy to Heroku, you will need to set the username and password as Heroku environment variables.

For Gmail:

$ heroku config:add GMAIL_USERNAME=myname@gmail.com GMAIL_PASSWORD=secret

or for Mandrill:

$ heroku config:add MANDRILL_USERNAME=myname MANDRILL_API_KEY=secret

and MailChimp:

$ heroku config:add MAILCHIMP_API_KEY=secret

Open a new shell or restart your terminal application to continue.

Configure Devise for Email

Complete your email configuration by modifying

config/initializers/devise.rb

and setting the config.mailer_sender option for the return email address for messages that Devise sends from the application.

Set Up the Database

Create a Default User

You’ll want to set up a default user so you can test the app. The file db/seeds.rb already contains:

puts 'SETTING UP DEFAULT USER LOGIN'
user = User.create! :name => 'First User', :email => 'user@example.com', :password => 'please', :password_confirmation => 'please'
user.confirm!
puts 'New user created: ' << user.name
user2 = User.create! :name => 'Second User', :email => 'user2@example.com', :password => 'please', :password_confirmation => 'please'
user2.confirm!
puts 'New user created: ' << user2.name
user.add_role :admin

You can change the values for name, email, and password as you wish.

If you include your private password in the file, be sure to add the filename to your .gitignore file so that your password doesn’t become available in your public GitHub repository.

Note that it’s not necessary to personalize the db/seeds.rb file before you deploy your app. You can deploy the app with an example user and then use the application’s “Edit Account” feature to change name, email address, and password after you log in.

Seed the Database

Set up the database and add the default users by running:

$ rake db:migrate
$ rake db:seed

You can reset the database anytime (though you’ll lose all data):

$ rake db:reset

If you’re not using rvm, the Ruby Version Manager, you should preface each rake command with bundle exec. You don’t need to use bundle exec if you are using rvm version 1.11.0 or newer.

Test Suite

Run the Cucumber integration test suite to see if everything works.

Be sure you’ve set up the database for testing:

$ rake db:test:prepare

Then we can run our integration test suite with the following command:

$ cucumber

Test the App

You can check that your app runs properly by entering the command

$ rails server

To see your application in action, open a browser window and navigate to http://localhost:3000/.

Sign in as the first user (the administrator) using:

  • email: user@example.com
  • password: please

You’ll see a navigation link for Admin. Clicking the link will display a page with a list of users at
http://localhost:3000/users.

To sign in as the second user, use

  • email: user2@example.com
  • password: please

The second user will not see the Admin navigation link and will not be able to access the page at
http://localhost:3000/users.

If you want to see what the admininstrative dashboard looks like with many users, you can add a line to the db/seeds.rb file to create a hundred bogus users:

100.times {|i| User.create! :name => "User #{i+3}", :email => "user#{i+3}@example.com", :password => 'please', :password_confirmation => 'please', :confirmed_at => (Time.now + i.day).utc, :created_at => (Time.now + i.day).utc  }

You’ll have to modify the file app/models/user.rb to allow mass assignment of the created_at field:

attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :confirmed_at, :created_at

Then run $ rake db:reset to recreate the database and visit the site again.

Deploy to Heroku

For your convenience, here are instructions for deploying your app to Heroku. Heroku provides low cost, easily configured Rails application hosting.

Where to Get Help

Please create a GitHub issue if you identify any problems or have suggestions for improvements.

Your best source for help with problems is Stack Overflow. Your issue may have been encountered and addressed by others.

You can also try Rails Hotline, a free telephone hotline for Rails help staffed by volunteers.

Contributing

If you make improvements to this application, please share with others.

Send the author a message, create an issue, or fork the project and submit a pull request.

If you add functionality to this application, create an alternative implementation, or build an application that is similar, please contact me and I’ll add a note to the README so that others can find your work.

Credits

Daniel Kehoe (http://danielkehoe.com/) implemented the application and wrote the tutorial.

Is the app useful to you? Follow the project on Twitter: @rails_apps
and tweet some praise. I’d love to know you were helped out by what I’ve put together.

MIT License

MIT License

Copyright © 2012 Daniel Kehoe

githalytics.com alpha