Browse files

new README

  • Loading branch information...
1 parent cbe1e21 commit c3dbd38063f878725fdb07439e77a6a60e631a15 @fortuity fortuity committed May 5, 2011
Showing with 346 additions and 23 deletions.
  1. +346 −23 README.textile
View
369 README.textile
@@ -1,59 +1,382 @@
-h1. Rails3 Mongoid Omniauth
+h1. Rails 3 + Mongoid + Omniauth
-Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+This is an example *Rails 3 application* that combines *OmniAuth* with *Mongoid*. It uses the "OmniAuth":https://github.com/intridea/omniauth gem to manage authentication using a service provider such as Twitter or Facebook. MongoDB is used as a datastore with the "Mongoid":http://mongoid.org/ gem for quick development without schemas or migrations.
-h2. More Information
+Best of all, there's a "detailed tutorial":https://github.com/fortuity/rails3-mongoid-omniauth/wiki/Tutorial (walk-through) to show how it's built.
-Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+* *Service Providers:* Facebook, Twitter, GitHub, LinkedIn, and "many more":https://github.com/intridea/omniauth.
+* *Gems:* Mongoid and OmniAuth plus optional jQuery, Haml, RSpec and Cucumber.
-h2. Required Gems
+You can clone this app or generate a new Rails application using this app as a template.
-This application requires this gem:
+h2. Follow on Twitter
-* "rails":http://rubygems.org/gems/rails
+To keep up to date with development of this app, follow the project on Twitter:
+"http://twitter.com/rails_apps":http://twitter.com/rails_apps.
+
+Any issues? Please create an "Issue":http://github.com/fortuity/rails3-mongoid-omniauth/issues on GitHub.
+
+h2. "Building It" Tutorial
+
+A complete walkthrough tutorial is available on the GitHub wiki:
+
+h4. "View the Tutorial":https://github.com/fortuity/rails3-mongoid-omniauth/wiki/Tutorial
+
+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 simply wish to modify the application for your own project, you can download the application and set it up as described below, without following the tutorial.
+
+h2. What Is Implemented -- and What Is Not
+
+This is a demonstration application that allows you to visit a home page and see a list of users. You can log in using a service provider such as Twitter and view a profile for each user. You can customize this app as you need.
+
+h4. Single Provider or Multiple Providers?
+
+This application is designed for sign-in with a *single provider*. For example, you may be creating an application just for Twitter users. Alternatively, it's possible to create an application that lets a user log in using *multiple providers*. For these more complex applications, see other examples and tutorials listed below.
+
+h4. When to use Devise?
+
+"Devise":http://github.com/plataformatec/devise provides authentication using username (or email address) and password. If you don't need the option of using a username/password, that is, if you wish to have all your users sign in using a service provider's account (such as Twitter or Facebook), there's no need to use Devise. Devise can be used in conjunction with the OmniAuth gem when you need to offer users the option of signing up for access to a website using an email address. For example, combine Devise with OmniAuth to a
+ccommodate users who want to log in with various service providers (Twitter, Facebook, etc.) as well as users who don't have external accounts and want to sign up with just an email address. See suggestions below for tutorials and examples that combine Devise with OmniAuth.
+
+h4. The Email Problem
+
+You don't need to ask a visitor for an email address when you build an application that allows a user to log in using a service provider such as Twitter or Facebook. You may consider that an advantage: if a user is logged in with Twitter or Facebook, they don't need to enter an email address and password to access your application. However, the lack of an email address may be a business drawback, if you want the opportunity to stay in contact with the user by email. Some service providers provide the user's email address to your application (Facebook). Some service providers only provide the email address at the user's option (GitHub supplies it if the user has provided a public email address). And other service providers do not provide the email address at all (Twitter, LinkedIn).
+
+This example app shows how to request an email address from the user when he or she first requests access to your application. It is easy to remove this feature if you don't require it.
+
+h4. Similar Examples and Tutorials
+
+|_. OmniAuth Examples and/or Tutorials |_. |_. Authors |
+| "Simple OmniAuth":http://railscasts.com/episodes/241-simple-omniauth | screencast | Ryan Bates |
+| "OmniAuth Pure":http://www.communityguides.eu/articles/16 | example and tutorial for OmniAuth with multiple providers | Markus Proske |
+| "Devise and OmniAuth":http://www.communityguides.eu/articles/11 | example and tutorial for OmniAuth and Devise with multiple providers | Markus Proske |
+| "rails3-mongoid-devise-omniauth":https://github.com/fertapric/rails3-mongoid-devise-omniauth | example and tutorial for Devise and OmniAuth with Mongoid | Fernando Tapia Rico |
+
+|_. Devise Examples and/or Tutorials |_. |_. Authors |
+| "rails3-devise-rspec-cucumber":https://github.com/fortuity/rails3-devise-rspec-cucumber | example and tutorial for Devise with ActiveRecord | Daniel Kehoe |
+| "rails3-mongoid-devise":https://github.com/fortuity/rails3-mongoid-devise | example and tutorial for Devise with Mongoid | Daniel Kehoe |
+
+h2. Obtaining API Keys
+
+Before installing the application, you may wish to contact the service provider you'll use to obtain any required API keys. The example assumes you will be using Twitter.
+
+h4. Twitter
+
+Visit "https://developer.twitter.com/apps/new":https://developer.twitter.com/apps/new to register your application. When you register your application, use the following values:
+
+|_. Application Website |_. Callback URL |_. Notes |
+| http://example.com | http://127.0.0.1:3000/ | http://localhost:3000/ doesn't work |
+
+h4. Facebook
+
+Visit "http://developers.facebook.com/setup":http://developers.facebook.com/setup to register your application.
+
+h4. GitHub
+
+Visit "https://github.com/account/applications/new":https://github.com/account/applications/new to register your application.
h2. Dependencies
-To use this application, you will need:
+Before running this app, you need to install
* The Ruby language (version 1.8.7 or 1.9.2)
-* Rails (version 3.0.4 or newer)
+* Rails
+* A working installation of "MongoDB":http://www.mongodb.org/ (version 1.6.0 or newer)
+
+I recommend installing rvm, the "Ruby Version Manager":http://rvm.beginrescueend.com/, to manage multiple versions of Rails.
+
+Check that appropriate versions of Ruby and Rails are installed in your development environment:
+@$ ruby -v@
+@$ rails -v@
+
+h4. Installing MongoDB
+
+If you don't have MongoDB installed on your computer, you'll need to install it and set it up to be always running on your computer (run at launch). On Mac OS X, the easiest way to install MongoDB is to install "Homebrew":http://mxcl.github.com/homebrew/ and then run the following:
+
+<pre>
+brew install mongodb
+</pre>
+
+Homebrew will provide post-installation instructions to get MongoDB running. The last line of the installation output shows you the MongoDB install location (for example, */usr/local/Cellar/mongodb/1.8.0-x86_64*). You'll find the MongoDB configuration file there. After an installation using Homebrew, the default data directory will be */usr/local/var/mongodb*.
+
+h2. Getting the Application
+
+You have several options for getting the code.
-h2. Installing the Application
+h4. Downloading the Code
-Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+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/fortuity/rails3-mongoid-omniauth.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/":http://git-scm.com/).
+
+h4. 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 "fortuity/rails3-application-templates":https://github.com/fortuity/rails3-application-templates repository.
+
+Use the command:
+
+@$ rails new APP_NAME -m https://github.com/fortuity/rails3-application-templates/raw/master/rails3-mongoid-omniauth-template.rb -T -J@
+
+Use the @-T -O -J@ flags to skip Test::Unit files, Active Record files, and Prototype files.
+
+bq. You MUST be using Rails 3.0.4 or newer. Generating a Rails application from an “HTTPS” URL does not work in Rails 3.0.3 and earlier versions.
+
+This creates a new Rails app (with the @APP_NAME@ you provide) on your computer.
+
+The application generator template will ask you for your preferences:
+
+* Would you like to use jQuery instead of Prototype?
+* Would you like to use jQuery UI?
+* Would you like to use Haml instead of ERB?
+* Would you like to use RSpec instead of TestUnit?
+* Would you like to use factory_girl for test fixtures with RSpec?
+* Would you like to use Cucumber for your BDD?
+* Would you like to use Mongoid to connect to a MongoDB database?
+* Would you like to use OmniAuth for authentication?
+* Which service provider will you use? (Twitter, Facebook, etc.)
+* Would you like to set a robots.txt file to ban spiders?
+
+h4. Use "Recipes" to Customize an Application Template
+
+The "tutorial":https://github.com/fortuity/rails3-mongoid-omniauth/wiki/Tutorial shows how a customized application template can be assembled from "recipes." The application template was created using the "rails3_devise_wizard":https://github.com/fortuity/rails3_devise_wizard gem which provides a convenient way to assemble a reusable application template by selecting various "recipes" for popular Rails development packages.
+
+h4. Please Remember: Edit the README
+
+If you're open sourcing the app on GitHub, please edit the README file to add a description of the app and your contact info. Changing the README is important if you're using a clone of the example app. I've been mistaken (and contacted) as the author of apps that are copied from my example.
h2. Getting Started
-Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+h4. About Required Gems
+
+The application uses the following gems. I recommend checking for newer versions of these gems before proceeding:
+
+* rails "(check rubygems.org for a newer gem)":http://rubygems.org/gems/rails
+* mongoid "(Check rubygems.org for a newer gem)":http://rubygems.org/gems/mongoid
+* bson_ext "(Check rubygems.org for a newer gem)":http://rubygems.org/gems/bson_ext
+* omniauth "(Check rubygems.org for a newer gem)":http://rubygems.org/gems/omniauth
+* rspec-rails "(Check rubygems.org for a newer gem)":http://rubygems.org/gems/rspec-rails
+* database_cleaner "(Check rubygems.org for a newer gem)":http://rubygems.org/gems/database_cleaner
+* factory_girl_rails "(Check rubygems.org for a newer gem)":http://rubygems.org/gems/factory_girl_rails
+* cucumber-rails "(Check rubygems.org for a newer gem)":http://rubygems.org/gems/cucumber-rails
+* capybara "(Check rubygems.org for a newer gem)":http://rubygems.org/gems/capybara
+
+The app has been tested with the indicated versions. If you are able to build the app with a newer gem, please create an "issue":http://github.com/fortuity/rails3-mongoid-omniauth/issues on GitHub and I will update the app.
+
+h4. 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.
+
+h4. Set Up Configuration for OmniAuth
+
+This app uses OmniAuth for user management and authentication. OmniAuth is at "https://github.com/intridea/omniauth":https://github.com/intridea/omniauth.
+
+You'll need an OmniAuth initialization file *config/initializers/omniauth.rb* set up for the service provider you'll use. For most service providers, you need to register your application and obtain API keys to use their authentication service.
+
+For Twitter:
+
+<pre>
+Rails.application.config.middleware.use OmniAuth::Builder do
+ provider :twitter, 'KEY', 'SECRET'
+end
+</pre>
+
+For Facebook:
+
+<pre>
+Rails.application.config.middleware.use OmniAuth::Builder do
+ provider :facebook, 'KEY', 'SECRET'
+end
+</pre>
+
+For others, see "Module: OmniAuth::Strategies":http://intridea.github.com/omniauth/OmniAuth/Strategies.html.
+
+h4. Keep Your API Keys Secret
+
+Make sure that the file *config/initializers/omniauth.rb* will not be added to your GitHub repository. If you've created a public repository and you commit the file with your API Keys, anyone who browses your repo will be able to obtain your API keys and masquerade as your application.
+
+Modify the *.gitignore* file before commiting the file with your API keys. Add:
+
+<pre>
+config/initializers/omniauth.rb
+</pre>
+
+You'll need to keep a local copy of the file and recreate it if you replace your local repo with a clone from a remote Git repository.
+
+h2. Using the Database Seed File to Reset the Datastore
+
+You'll want a convenient way to reset the datastore. The file *db/seeds.rb* is set up to reset the MongoDB database.
+
+<pre>
+puts 'EMPTY THE MONGODB DATABASE'
+Mongoid.master.collections.reject { |c| c.name =~ /^system/}.each(&:drop)
+</pre>
+
+When you wish to reset the MongoDB datastore you can run the command:
+
+@$ rake db:seed@
+
+You can also use the *db/seeds.rb* file to initialize the datastore by creating and saving any model instances you need.
+
+h4. 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/":http://localhost:3000. You should see the default user listed on the home page. When you click on the user's name, you should be required to log in before seeing the user's profile page.
+
+h2. Deploy to Heroku
+
+h4. Set Up Heroku
+
+For your convenience, here are instructions for deploying your app to Heroku. Heroku provides low cost, easily configured Rails application hosting.
+
+To deploy this app to Heroku, you must have a Heroku account. If you need to obtain one, visit "http://heroku.com/":http://heroku.com/ to set up an account.
+
+Make sure the Heroku gem is in your *Gemfile* "(check rubygems.org for the latest heroku gem)":http://rubygems.org/gems/heroku:
+
+@gem "heroku", ">= 1.19.1"@
+
+If it's not, add it and run
+
+@$ bundle install@
+
+to set up your gems again.
+
+Add your public key immediately after installing the heroku gem so that you can use git to push or clone Heroku app repositories. See "http://devcenter.heroku.com/articles/heroku-command":http://devcenter.heroku.com/articles/heroku-command for details.
+
+h4. Create Your Application on Heroku
+
+Use the Heroku create command to create and name your new app.
+
+@$ heroku create _myapp_@
+
+As of 9 February 2011, bamboo-ree-1.8.7 is the default stack for new Heroku apps.
+
+If you want to use Ruby 1.9.2, you can create your app with:
+
+@heroku create _myapp_ --stack bamboo-mri-1.9.2@
+
+h4. Heroku Add-on for MongoHQ
+
+You can use a Heroku add-on to deploy your app using the MongoHQ service. See "details about the service":http://addons.heroku.com/mongohq and "details about installation":http://devcenter.heroku.com/articles/mongohq.
+
+To enable the add-on, you can use the Heroku web interface or you can enter the following commands:
+
+@$ heroku addons:add mongohq:free@
+
+h4. Check Heroku Configuration
+
+You can check that everything has been added correctly by running:
+
+@$ heroku info --app myapp@
+
+If you see @Stack: bamboo-ree-1.8.7@ and you want to use Ruby 1.9.2, you can migrate:
+
+@heroku stack:migrate bamboo-mri-1.9.2@
+
+h4. Push Your Application to Heroku
+
+Push your application to Heroku:
+
+@$ git push heroku master@
+
+Initialize your application database:
+
+@$ heroku rake db:seed@
+
+h4. Fix Problems Connecting to MongoHQ
+
+If you get the error message "failed to connect to any given host:port" or "Failed to connect to a master node at localhost:27017", the *config/mongoid.yml* file may not have the correct MongoHQ connection parameters.
+
+If the file *config/mongoid.yml* contains this:
+
+<pre>
+# set these environment variables on your prod server
+production:
+ host: <%= ENV['MONGOID_HOST'] %>
+ port: <%= ENV['MONGOID_PORT'] %>
+ username: <%= ENV['MONGOID_USERNAME'] %>
+ password: <%= ENV['MONGOID_PASSWORD'] %>
+ database: <%= ENV['MONGOID_DATABASE'] %>
+</pre>
+
+modify it to look like this:
+
+<pre>
+# set these environment variables on your prod server
+production:
+ uri: <%= ENV['MONGOHQ_URL'] %>
+</pre>
+
+Then push your application to Heroku again with @$ git push heroku master@ and run @$ heroku rake db:seed@ again.
+
+h4. Visit Your Site
+
+Open your Heroku site in your default web browser:
+
+@$ heroku open@
+
+h4. Troubleshooting
+
+If you get errors, you can troubleshoot by reviewing the log files:
+
+@$ heroku logs@
+
+h2. Testing
+
+The application contains RSpec unit tests and Cucumber scenarios and steps. The tests are minimal and can be improved.
+
+Please send the author a message, create an issue, or submit a pull request if you can contribute improved RSpec or Cucumber files.
+
+After installing the application, run @rake -T@ to check that rake tasks for RSpec and Cucumber are available.
+
+Run @rake spec@ to run all RSpec tests.
+
+Run @rake cucumber@ (or more simply, @cucumber@) to run all Cucumber scenarios and steps.
+
+You can browse and search the Cucumber features at the "Relish":http://relishapp.com/fortuity/rails3-mongoid-omniauth website.
h2. Documentation and Support
This is the only documentation.
-h4. Issues
-
-Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+Ryan Bates offers a "Railscast on Simple OmniAuth":http://railscasts.com/episodes/241-simple-omniauth. You can find documentation for "OmniAuth":https://github.com/intridea/omniauth at "https://github.com/intridea/omniauth":https://github.com/intridea/omniauth. There is an active "OmniAuth mailing list":http://groups.google.com/group/omniauth and you can submit "OmniAuth issues":https://github.com/intridea/omniauth/issues at GitHub.
-h2. Similar Projects
+h4. Issues
-Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+Please create an "Issue":http://github.com/fortuity/rails3-mongoid-omniauth/issues on GitHub if you identify any problems or have suggestions for improvements.
h2. Contributing
If you make improvements to this application, please share with others.
-* Fork the project on GitHub.
-* Make your feature addition or bug fix.
-* Commit with Git.
-* Send the author a pull request.
+Send the author a message, create an "issue":http://github.com/fortuity/rails3-mongoid-omniauth/issues, 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.
h2. Credits
-Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+Daniel Kehoe ("http://danielkehoe.com/":http://danielkehoe.com/) implemented the application and wrote the tutorial.
+
+Is the app useful to you? Follow the project on Twitter:
+"http://twitter.com/rails_apps":http://twitter.com/rails_apps
+and tweet some praise. I'd love to know you were helped out by what I've put together.
h2. License
-Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+h4. Public Domain Dedication
+
+This work is a compilation and derivation from other previously released works. With the exception of various included works, which may be restricted by other licenses, the author or authors of this code dedicate any and all copyright interest in this code to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this code under copyright law.
+

0 comments on commit c3dbd38

Please sign in to comment.