“Building It” 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. Refer to the Rails Guides site for help if you are a beginner. Or read Michael Hartl’s Ruby on Rails Tutorial book.

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.

Integrates Devise, Roles, and CanCan with Permits. For Mongoid or other ORMs.

What Is Implemented — and What Is Not

This is a barebones application that serves to demonstrate Mongoid and Devise working on Rails 3.

All you can do is visit a home page and see a list of users. With the default user’s email and password (supplied below), you can log in and view details for each user. You can customize this app as you need.

If you are using rvm, you can see a list of the Ruby versions currently installed:$ rvm list

Check that appropriate versions of Ruby and Rails are installed in your development environment:$ ruby -v$ rails -v

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 and then run the following:

brew install mongo
sudo mkdir -p /data/db
sudo chmod -Rv 777 /data/

Getting the Application

You have several options for getting the code.

Downloading the Code

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-devise.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/).

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 repository.

Use the -T -O -J flags to skip Test::Unit files, Active Record files, and Prototype files.

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 template offers you the following options:

set up your view files using the Haml templating language

use jQuery instead of Prototype as a Javascript framework

use RSpec instead of TestUnit for unit testing

use Cucumber for Behavior Driven Development

install the heroku gem for deployment to Heroku

use Yard instead of RDoc for documentation

Use “Recipes” to Customize an Application Template

The tutorial shows how a customized application template can be assembled from “recipes.” You can use the RailsWizard.org web site to create your own custom application template, adding any template recipes you want from the rails-template-recipes repository.

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 with this very helpful README file. I’ve already been mistaken (and contacted) as the author of apps that are copied from my example. It’s amusing for me but annoying for others.

Getting Started

About Required Gems

The application uses the following gems. I recommend checking for newer versions of these gems before proceeding:

Use the defaults or change the values for name, email, and password as you wish.

Seed the Database

Add the default user to the MongoDB database by running the command:

$ rake db:seed

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/. 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 detail page.

To sign in as the default user, (unless you’ve changed it) use

email: user@test.com

password: please

You should delete or change the pre-configured logins before you deploy your application.

Heroku Add-on for 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

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

Push Your Application to Heroku

Push your application to Heroku:

$ git push heroku master

Initialize your application database:

$ heroku rake db:seed

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.

This application is provided without additional documentation or support.

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.

Contributors

License

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.