Contour <img src=“https://secure.travis-ci.org/remomueller/contour.png”/> <img src=“https://gemnasium.com/remomueller/contour.png” alt=“Dependency Status” /> <img src=“https://codeclimate.com/badge.png” />

Basic Rails framework files and assets for layout and authentication

Installation

Contour can be installed from rubygems.org using

gem install contour

Or update your Gemfile to include

gem 'contour'

Getting started

Make sure you have Rails 3.2.10

rails -v

rails new blank_rails_project

cd blank_rails_project

Modify Gemfile and add

gem 'contour', '~> 1.1.2'

Run Bundle install

bundle install

Install contour files

rails generate contour:install

Add the authentication model

rails generate model Authentication user_id:integer provider:string uid:string

Migrate your database

bundle exec rake db:create

bundle exec rake db:migrate

Create a sample controller

rails generate controller welcome index --skip-stylesheets

Remove the public/index.html

rm public/index.html

Add the following line to your app/controllers/application_controller.rb

layout "contour/layouts/application"

Edit your app/assets/javascripts/application.js manifest to use Contour JavaScript (Replace jquery and jquery_ujs)

//= require contour

Edit your app/assets/stylesheets/application.css manifest to use Contour CSS (after self, before tree)

*= require contour

Make sure the devise line in config/routes.rb looks as follows

devise_for :users, controllers: { registrations: 'contour/registrations', sessions: 'contour/sessions', passwords: 'contour/passwords', confirmations: 'contour/confirmations', unlocks: 'contour/unlocks' }, path_names: { sign_up: 'register', sign_in: 'login' }

If there is a line that just says devise_for :users or a duplicate, REMOVE IT!

Create a root in your config/routes.rb

root to: 'welcome#index'

Add the following to the top of your app/controllers/welcome_controller.rb

before_filter :authenticate_user!

Add the following to your app/models/user.rb

# Model Relationships
has_many :authentications

def apply_omniauth(omniauth)
  unless omniauth['info'].blank?
    self.email = omniauth['info']['email'] if email.blank?
  end
  authentications.build( provider: omniauth['provider'], uid: omniauth['uid'] )
end

def password_required?
  (authentications.empty? || !password.blank?) && super
end

Add the following to your app/models/authentication.rb

belongs_to :user

def provider_name
  OmniAuth.config.camelizations[provider.to_s.downcase] || provider.to_s.titleize
end

Edit config/initializers/devise.rb to use :get for devise sign_out_via

# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :get

Start your server and navigate to localhost:3000/users/login

rails s

You can then sign in using your Google Account or by registering for an account at localhost:3000/users/register

Overwrite Default Rails Scaffolding (optional)

Add Kaminari gem to your Gemfile

gem 'kaminari', '~> 0.14.1'

Update your gems

bundle update

Create a new model using the Rails scaffold

rails g scaffold Item name:string description:text user_id:integer bought_date:date --no-stylesheets

Add a current scope and belongs_to relationship to app/models/item.rb

scope :current, conditions: { }

belongs_to :user

Add a current scope and has_many relationship to app/models/user.rb along with name placeholder

scope :current, conditions: { }

has_many :items

def name
  "User ##{self.id}"
end

Add a user resource to your config/routes.rb file

resources :users

NOTE: Adding the User controller is not shown, but could be created using rails g controller Users index show edit update destroy --no-stylesheets. Remember that the new and create actions are already defined and should be left commented out.

Migrate your database

bundle exec rake db:migrate

Update with the Contour scaffold

rails g contour:scaffold Item

When prompted to overwrite the existing files, type a for ALL.

NOTE: This will overwrite all the files generated by the rails scaffold command!

Go to localhost:3000/items to see the changes! Note, that the user_id selection now defaults to a drop down box!

Inspiration and Attribution

Contour is designed to rapidly prototype Rails applications with nice default styling and a solid authentication system. The Contour code base has been influenced by existing Rails Engines architectures that are listed below. Please check them out if you are interested in seeing how Contour is put together!

Devise

Devise is the highly configurable authentication gem that Contour utilizes.

Contour has adopted Devise’s installation and configuration approach rails generate devise:install and config/intializers/devise.rb.

Twitter Bootstrap Rails

While Contour doesn’t have an external dependency on the Twitter Bootstrap Rails gem, Contour does adopt the templating approach, rails generate contour:scaffold ModelName, used to overwrite the default scaffolding provided by Rails.

For those interested in having better control on modifying the Twitter Bootstrap Less file and CSS, I highly recommend taking a look at Twitter Bootstrap Rails!

Contributing to Contour

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright <img style=“border-width:0” src=“http://i.creativecommons.org/l/by-nc-sa/3.0/80x15.png”/>

Copyright © 2013 Remo Mueller. See LICENSE for further details.