Blog ยป Template for DRYer rails demo blog
Posted on 17 Aug 2012 14:15
In Getting Started with DRYer Rails 3.2, I showed how small code you need to create a blog or any other application. But where is the code to try? Here is the rails template to create a DRY demo blog for you. Simply do
rails new demo_blog -m https://raw.github.com/gist/3378950/699589853464e4654ae7e5d183de126b11f4720f/template_umur_demo_blog.rb #Note that you need bundler and rails gems in your system or current rvm environment.
#Usage example: rails new demo_blog -m demo_blog_recipe.rb # 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
Note that you need bundler and rails gems in your system or current rvm environment.
Andrea Singh describes a cool way to create a new rvm gemset for your new project down in section "Using RVM". I advice you to use her bootstrap.rb. I am thinking about making it a global Thor script.
If you like this page, please spread the word:
You can contact me if you have questions or corrections.