Rails 3.2 example application for a “beta launching soon” startup prelaunch signup site.
- Rails Prelaunch Signup App project page
Best of all, there’s a detailed tutorial to show how it is built.
You can build this application in only a few minutes using the Rails Composer tool.
Read an interview with Michael Gajda about how he used the project to launch his startup site.
Alternative version | Author | |
---|---|---|
rails-prelaunch-signup-1click | single-click email submit (no modal) | Chad Kruse |
Follow the project on Twitter: @rails_apps. Please tweet some praise if you like what you’ve found.
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.
This is a complete and fully functional application.
- 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
- administrative dashboard page
- list of all visitors who have requested invitations
- 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”
- 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
- write user stories
- use Devise for user management and authentication
- use CanCan for role-based authorization
- keep account passwords secret using environment variables
- use git and GitHub for source control
- deploy using Heroku
- queuing (asynchronous processing) for transactional email and MailChimp list capture
- caching
- A/B testing of offers
- Google analytics
- “about” and “contact” pages
If you add features or improve the implementation, please consider contributing by submitting an issue or pull request from your fork.
This is an application for Rails developers who wish to deploy their own application. 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.
Unlike a service such as LaunchRock, KickoffLabs and Unbounce, you’ll have your own application you can customize as you wish. Just as important, when your visitors sign up, they are creating real user accounts in a user management system you can use after you launch.
If you do not want to build an application, or you are not a Rails developer, you may wish to consider alternatives.
- 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 are a popular way to stage a startup prelaunch page.
- Launch Effect – “a WordPress theme for viral launches”
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.
Here are some articles that describe the purpose and options for a startup prelaunch page:
- Building An Effective ‘Coming Soon’ Page for Your Product from Smashing Magazine
- Elements Of A Viral Launch Page from Smashing Magazine
- Which Are the Best Startup Prelaunch Pages? from Quora
Have other suggestions? Please create an issue with your suggestion or email the author.
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.
A complete tutorial is available:
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. If you’re new to Rails, see recommendations for a Rails tutorial and a list of top resources for Ruby and Rails. The article What is Ruby? And Rails? is a good place to get a basic introduction to 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.
Before generating your application, you will need:
- The Ruby language (version 1.9.3 or 2.0.0)
- The Rails gem (version 3.2.13)
See Installing Rails for detailed instructions and advice.
Before you start, you may need to set up accounts for hosting and email.
For easy deployment, use a “platform as a service” provider such as:
Instructions are provided for deployment to Heroku.
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).
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).
You have several options for getting the code. You can fork, clone, or generate.
If you’d like to add features (or bug fixes) to improve the example application, you can fork the GitHub repo and make pull requests. Your code contributions are welcome!
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. You’ll need to search-and-replace the project name throughout the application. You probably should generate the app instead (see below). To clone:
$ git clone git://github.com/RailsApps/rails-prelaunch-signup.git
You’ll need git on your machine. See Rails and Git.
If you want to use the project as a starter app, use the Rails Composer tool to generate a new version of the example app. You’ll be able to give it your own project name when you generate the app. Generating the application gives you many additional options.
To build the example application, run the command:
$ rails new rails-prelaunch-signup -m https://raw.github.com/RailsApps/rails-composer/master/composer.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.
You’ll see a prompt:
question Install an example application? 1) I want to build my own application 2) membership/subscription/saas 3) rails-prelaunch-signup 4) rails3-bootstrap-devise-cancan 5) rails3-devise-rspec-cucumber 6) rails3-mongoid-devise 7) rails3-mongoid-omniauth 8) rails3-subdomains
Choose rails-prelaunch-signup. The Rails Composer tool may give you other options (other choices may have been added since these notes were written).
The application generator template will ask you for additional 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 Use or create a project-specific rvm gemset? (y/n) extras Create a GitHub repository? (y/n)
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.
We recommend Thin in development for speed and less noise in the log files.
If you plan to deploy to Heroku, select Thin as your production webserver.
The example application uses the default “ERB” Rails template engine. Optionally, you can use another template engine, such as Haml or Slim. See instructions for Haml and Rails.
Set a robots.txt file to ban spiders if you want to keep your new site out of Google search results.
It is a good idea to use rvm, the Ruby Version Manager, and create a project-specific rvm gemset (not available on Windows). See Installing Rails.
If you choose to create a GitHub repository, the generator will prompt you for a GitHub username and password.
If you get an error “OpenSSL certificate verify failed” or “Gem::RemoteFetcher::FetchError: SSL_connect” see the article OpenSSL errors and Rails.
If you get an error like this:
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. composer Running 'after bundler' callbacks. The template [...] could not be loaded. Error: You have already activated ..., but your Gemfile requires .... Using bundle exec may solve this.
It’s due to conflicting gem versions. See the article Rails Error: “You have already activated (…)”.
If you’re storing the app in a GitHub repository, please edit the README files to add a description of the app and your contact info. If you don’t change the README, people will think I am the author of your version of the application.
See the article Installing Rails to make sure your development environment is prepared properly.
I recommend using rvm, the Ruby Version Manager, to create a project-specific gemset for the application. If you generate the application with the Rails Composer tool, you can create a project-specific gemset.
Check the Gemfile to see which gems are used by this application.
If you used the Rails Composer tool to generate the example app, the application template script has already run the bundle install
command.
If not, you should run the bundle install
command to install the required gems on your computer:
$ bundle install
You can check which gems are installed on your computer with:
$ gem list
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.
I recommend using rvm, the Ruby Version Manager, to create a project-specific gemset for the application. See the article Installing Rails.
You must configure the application for your email account. See the article Send Email with Rails.
You can modify the configuration file for Devise if you want to use something other than the defaults:
- config/initializers/devise.rb
The application uses the figaro gem to set environment variables. Credentials for your administrator account and email account are set in the config/application.yml file. The .gitignore file prevents the config/application.yml file from being saved in the git repository so your credentials are kept private. See the article Rails Environment Variables for more information.
Modify the file config/application.yml:
# Add account credentials and API keys here. # See http://railsapps.github.io/rails-environment-variables.html # This file should be listed in .gitignore to keep your settings secret! # Each entry sets a local environment variable and overrides ENV variables in the Unix shell. # For example, setting: # GMAIL_USERNAME: Your_Gmail_Username # makes 'Your_Gmail_Username' available as ENV["GMAIL_USERNAME"] # Add application configuration variables here, as shown below. # MANDRILL_USERNAME: Your_Username MANDRILL_API_KEY: Your_Mandrill_API_Key MAILCHIMP_API_KEY: Your_MailChimp_API_Key MAILCHIMP_LIST_ID: My_List_ID ADMIN_NAME: First User ADMIN_EMAIL: [email protected] ADMIN_PASSWORD: changeme ROLES: [admin, user] EMAIL_ADDRESS: [email protected] DOMAIN: example.com
We use Mandrill to increase deliverability for email messages from the application. Provide a MANDRILL_USERNAME
and MANDRILL_API_KEY
.
When visitors sign up to be notified of our launch, we’ll add them to a MailChimp list. Add an environment variable for the MailChimp API key: MAILCHIMP_API_KEY
. You can find the MailChimp API key under the tab for “Account” on the MailChimp website after you log in. Look for the “Api Keys and Authorized Apps” menu item.
We’ll add MAILCHIMP_LIST_ID
for the ID of the mailing list we’ll set up in MailChimp. To find the list ID, on the MailChimp “Lists” page, look for the dropdown “gear” menu for the mailing list you’ve created and click “List Settings and Unique ID.” At the bottom of the List Settings page, you’ll find the unique ID for the mailing list.
If you wish, set your name, email address, and password for an administrator’s account. If you prefer, you can use the default to sign in to the application and edit the account after deployment. It is always a good idea to change the administrator’s password after the application is deployed.
Specify roles in the configuration file. You will need an “admin” role and “user” role. Remove the “VIP” role as we won’t use it.
We’ll add EMAIL_ADDRESS
to provide the default sender email address we use when sending email from the application.
Finally, we’ll add DOMAIN
which is also used when sending email.
All configuration values in the config/application.yml file are available anywhere in the application as environment variables. For example, ENV["GMAIL_USERNAME"]
will return the string “Your_Username”.
If you prefer, you can delete the config/application.yml file and set each value as an environment variable in the Unix shell.
The db/seeds.rb file initializes the database with default values. To keep some data private, and consolidate configuration settings in a single location, we use the config/application.yml file to set environment variables and then use the environment variables in the db/seeds.rb file.
puts 'ROLES' YAML.load(ENV['ROLES']).each do |role| Role.find_or_create_by_name({ :name => role }, :without_protection => true) puts 'role: ' << role end puts 'DEFAULT USERS' user = User.find_or_create_by_email :name => ENV['ADMIN_NAME'].dup, :email => ENV['ADMIN_EMAIL'].dup, :password => ENV['ADMIN_PASSWORD'].dup, :password_confirmation => ENV['ADMIN_PASSWORD'].dup puts 'user: ' << user.name user.add_role :admin user.skip_confirmation! user.save!
The db/seeds.rb file reads a list of roles from the config/application.yml file and adds the roles to the database. In fact, any new role can be added to the roles datatable with a statement such user.add_role :superhero
. Setting the roles in the db/seeds.rb file simply makes sure each role is listed and available.
You can change the administrator name, email, and password in this file but it is better to make the changes in the config/application.yml file to keep the credentials private. If you decide to include your private password in the db/seeds.rb 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. Use this feature to log in as an administrator and change the user name and password to your own.
Don’t overlook the user.skip_confirmation!
and user.save!
statements. This application uses the Devise Confirmable module to require that a user confirm a new account by clicking on a link in an email message. You won’t be sending the administrator an email message with a confirmation link so you must set the account with the user.skip_confirmation!
and user.save!
statements.
You may wish to include additional sample users:
user2 = User.find_or_create_by_email :name => 'Second User', :email => '[email protected]', :password => 'changeme', :password_confirmation => 'changeme' puts 'user: ' << user2.name user2.add_role :VIP
This will add a second user to the database with a “VIP” role.
Prepare the database and add the default user to the database by running the commands:
$ rake db:migrate $ rake db:seed
Use rake db:reset
if you want to empty and reseed the database.
Set the database for running tests:
$ rake db:test:prepare
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.
If you’ve used the Rails Composer tool to generate the application, the application’s secret token will be unique, just as with any Rails application generated with the rails new
command.
However, if you’ve cloned the application directly from GitHub, it is crucial that you change the application’s secret token before deploying your application in production mode. Otherwise, people could change their session information, and potentially access your site without permission. Your secret token should be at least 30 characters long and completely random.
Get a unique secret token:
rake secret
Edit your config/initializers/secret_token.rb file to add the secret token:
RailsPrelaunchSignup::Application.config.secret_token = '...some really long, random string...'
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: [email protected]
- password: changeme
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.
If you want to see what the administrative 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 => 'changeme', :password_confirmation => 'changeme'}
Then run $ rake db:reset
to recreate the database and visit the site again.
Heroku provides low cost, easily configured Rails application hosting.
For your convenience, here is a Tutorial for Rails on Heroku. See the article for details about preparing your application to deploy to Heroku.
Be sure to set up SSL before you make your application available in production. See the Heroku documentation on SSL or use CloudFlare as described in the tutorial.
After you’ve prepared your application as described in the Tutorial for Rails on Heroku article, precompile assets, commit to git, and push to Heroku:
$ rake assets:precompile $ git add -A $ git commit -m "assets compiled for Heroku" $ git push heroku master
You’ll need to set the configuration values from the config/application.yml file as Heroku environment variables. See the article Rails Environment Variables for more information.
With the figaro gem, just run:
$ rake figaro:heroku
Alternatively, you can set Heroku environment variables directly.
Here’s how to set environment variables directly on Heroku with heroku config:add
.
$ heroku config:add MANDRILL_USERNAME='Your_Username' MANDRILL_API_KEY='Your_Mandrill_API_Key' $ heroku config:add MAILCHIMP_LIST_ID='Your_List_ID' $ heroku config:add ADMIN_NAME='First User' ADMIN_EMAIL='[email protected]' ADMIN_PASSWORD='changeme' $ heroku config:add 'ROLES=[admin, user]' $ heroku config:add EMAIL_ADDRESS='[email protected]' DOMAIN='example.com'
Complete Heroku deployment with:
$ heroku run rake db:migrate $ heroku run rake db:seed
The example application contains a suite of RSpec unit tests and Cucumber scenarios and step definitions.
After installing the application, run rake -T
to check that rake tasks for RSpec and Cucumber are available.
Run rake spec
to run RSpec tests.
Run rake cucumber
(or more simply, cucumber
) to run Cucumber scenarios.
Please send the author a message, create an issue, or submit a pull request if you can contribute improved RSpec or Cucumber files.
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.
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.
Daniel Kehoe 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.
Copyright © 2012 Daniel Kehoe