Rails: barebones site template from the ground up, version II, using rails 4

Assuming you have rails 4 already running in your system. And git / heroku also ready to go.

$ rails new your-project

Add a bunch of static pages, remove the default page:
remove public/index.html (if there)
$ rails generate controller StaticPages home help about contact_us –no-test-framework
Inside config/routes.rb”
– Comment out the static pages you don’t need, or add the right routes to the ones you want:
# get “contact_us” => “static_pages#contact_us” (example)
– Add a default page as home:
root :to => “static_pages#home”

Add devise, and their views:
Modify your gem file to contain the following lines:
gem ‘devise’
gem ‘sqlite3’, group: [:development, :test]
gem ‘pg’, group: :production

$ bundle install –without production
$ rails generate devise:install # Follow the instructions printed

$ rails generate devise user
$ rake db:migrate
To be able to modify the devise views as any other template:
$ rails generate devise:views

Add source control, push to Heroku
$ git init
$ git add .
$ git commit -am “Initial commit”
$ heroku login # if you haven’t
$ heroku create [name of your app]
$ git push heroku master
$ heroku run rake db:migrate

Static assets

If images and such are not showing on heroku production, you may have to pre compile them locally, using the following command:

RAILS_ENV=production bundle exec rake assets:precompile

This will generate the static assets inside the public directory. Ideally you should use a CDN to serve your images, but this should be ok for small projects.

Extra gems you may need for Rails 4.0

gem ‘rails_12factor’, group: :production

That will take care of any errors related to assest

Leave a Reply

Your email address will not be published. Required fields are marked *