Create a gist now

Instantly share code, notes, and snippets.

Rails 3 template to create a demo blog
# Usage example: rails new demo_blog -m template_umur_demo_blog.rb
# 2 points demonstrated
# - Templates are powerful. You can create even a working application
# - Ruby on Rails is very DRY. Code reads as if it's design
# Required gems
gem 'therubyracer', :platforms => :ruby, :group=>:assets #Rails need
gem 'inherited_resources'
gem 'has_scope'
append_file 'Gemfile' do
<<-EOS
git 'git://github.com/tablatom/hobo.git' do
gem 'hobo_fields'
#gem 'dryml'
gem 'hobo_support'
#gem 'hobo'
end
EOS
end
# Custom generators for DRY code
append_file 'config/application.rb' do
<<-EOS
#{@app_name.camelize}::Application.configure do
config.generators do |g|
g.test_framework :shoulda
g.fallbacks[:shoulda] = :test_unit
g.fixture_replacement :factory_girl
g.scaffold_controller :inherited_resources_controller
g.orm 'hobo'.to_sym
#TODO: Introduce steak/capybara for integration test
end
end
EOS
end
git :init
git :add => "."
git :commit => "-a -m 'Initial commit'"
####
# Let's make a demo blog now
####
say ("Installing gems so that we can scaffold...")
run 'bundle install'
generate :scaffold, 'Post title:string text:text'
route "root :to => 'posts#index'"
inject_into_class 'app/models/post.rb', 'Post' do
<<-EOS
attr_accessible :title, :text
default_scope :order => 'created_at DESC'
validates :title, :presence => true,
:length => { :minimum => 5 }
EOS
end
inject_into_class 'app/controllers/posts_controller.rb', 'PostsController' do
<<-EOS
respond_to :html, :json
EOS
end
rake("db:migrate")
# More template commands are in
# http://rdoc.info/github/wycats/thor/master/Thor/Actions.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment