Skip to content

Instantly share code, notes, and snippets.

@thenickcox
Last active December 14, 2015 05:29
Show Gist options
  • Save thenickcox/5036171 to your computer and use it in GitHub Desktop.
Save thenickcox/5036171 to your computer and use it in GitHub Desktop.
My Rails template (borrowing heavily from [Rails Application Templates](http://guides.rubyonrails.org/generators.html#application-templates) and [Everyday Rails](http://everydayrails.com/2011/02/28/rails-3-application-templates.html)
# create rvmrc file
create_file ".rvmrc", "rvm gemset use #{app_name}"
# Because Rails always seems to fail without it locally
gem 'pysch'
gem "haml-rails"
# hpricot and ruby_parser required by haml
gem "hpricot", :group => :development
gem "ruby_parser", :group => :development
gem "nifty-generators"
gem "simple_form"
gem "jquery-rails"
# authentication and authorization
if yes?("Do you need to install devise and cancan?")
gem "devise"
gem "cancan"
generate("devise:install")
model_name = ask("What would you like the user model to be called? [user]")
model_name = "user" if model_name.blank?
generate("devise", model_name)
end
# rspec, factory girl, webrat, autotest for testing
gem "rspec-rails", :group => [ :development, :test ]
gem "factory_girl_rails", :group => [ :development, :test ]
gem "faker", :group => :test
gem "capybara", :group => :test
gem "database_cleaner", :group => :test
gem "shoulda-matchers", :group => :test
gem 'coffee-rails', :group => :assets
run 'bundle install'
rake "db:create", :env => 'development'
rake "db:create", :env => 'test'
generate 'nifty:layout --haml'
remove_file 'app/views/layouts/application.html.erb' # use nifty layout instead
generate 'simple_form:install'
generate 'nifty:config'
remove_file 'public/javascripts/rails.js' # jquery-rails replaces this
generate 'rspec:install'
inject_into_file 'spec/spec_helper.rb', "\nrequire 'factory_girl'", :after => "require 'rspec/rails'"
inject_into_file 'config/application.rb', :after => "config.filter_parameters += [:password]" do
<<-eos
# Customize generators
config.generators do |g|
g.stylesheets false
g.form_builder :simple_form
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
end
eos
end
run "echo '--format documentation' >> .rspec"
# authentication and authorization setup
generate "devise:install"
generate "devise User"
generate "devise:views"
rake "db:migrate"
generate "cancan:ability"
# clean up rails defaults
remove_file 'public/index.html'
remove_file 'rm public/images/rails.png'
run 'cp config/database.yml config/database.example'
run "echo 'config/database.yml' >> .gitignore"
# commit to git
git :init
git :add => "."
git :commit => "-a -m 'create initial application'"
say <<-eos
============================================================================
Great work. Your new Rails application is ready to go. You deserve a raise.
Don't forget to scroll up for important messages from installed generators.
eos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment