Save Web Application Development Time Through Custom Rails Application Templates

Date Published:
Last Modified: by

I enjoy writing Rails applications. The Rails framework is mature and has become a very flexible development environment. Given that everybody has a slightly different way of dealing with day to day issues. Things tend to slows down and become more complicated as a framework matures and attempts to meet every bodies needs.

With Rails, I usually spend some time tweaking the initial application to get it to conform to the way that I want. This includes getting certain gems integrated into the application that I use in development. Wouldn't it be nice if I could customize this and save time?

Rails allows for the customization of applications through a Rails Application Template. An application template is a simple ruby file that uses a Domain Specific Language for adding gems/initializers. The documentation states that the template is evaluated in the context of a Rails::Generators::AppGenerator instance. This means that it is called using the apply action of Thor. So you can use the actions provided by the Thor gem to perform file operations, run command, and insert content into files.

By using my own application template I can create a default rails application configured to meet my requirements. This saves me valuable development time.

My Custom Rails Application Template

I like to use the following gems: Thin, Compass-Rails, Modernizr, Susy, RSpec, and Capybara. I also like to use BetterErrors and RailsPanel for debugging. Some require source code tweaks before they are fully functional in the application. This can be automated with the custom Rails Application Template shown below.

<script src="https://gist.github.com/rdhiggins/8357835.js"&gt;&lt;/script>

The script starts out by replacing the README.rdoc file with a skeleton README.md file. It also includes the list of gems that I typically use.

The RSpec bundle needs to be installed in order to initialize RSpec support under rails. This requires that the "bundle install" command is run. After this command has executed the generate "rspec:install" command can be called. Capybara requires a "spec/features" directory.

The remaining portion of the template performs the file modifications that fully integrate the gems into the application. This is accomplished using the Thor method inject_into_file.

Compass support is realized through changing the application.css file into an 'application.css.scss' file. This new file contains the basic imports for compass and well and suzy for grid development.

Capybara support is inserted into the 'spec/spec_helper.rb' file. BetterErrors only requires a custom initializer when you are not using the default editor. In my case I Use Sublime Text.

The next section modifies the 'application.html.erb' file to support HTML5 Boiler plate page structure. This also includes the addition of the Modernizr javascript library and common viewport meta tags.

The template asks the user if they want a root controller generated. The template then calls the generate command and then installs a root route.

The last section of the script performs the steps to initialize a Git repository.

Other Possibilities

There are other possibilities if a custom application template is not your cup of tea. Numerous sources of templates can be found by performing a google search. Rails Composer is also worth checking out. It provides a 'composer.rb' template that supports a large number of configuration options.

References

  1. Rails Application Template documentation
  2. Rails Composer
  3. Custom Rails Application Template Gist
  4. Thor
  5. Thor Actions
  6. Thin
  7. Compass-Rails
  8. Modernizr
  9. Susy
  10. RSpec
  11. Capybara
  12. BetterErrors
  13. RailsPanel

Recent Articles

A Reusable Observer Protocol Written In Swift

One design pattern that I use a lot is the observer pattern. The observer pattern is used when you have an object that needs to notify a list of objects that state changes have happened. This article discusses a reusable component, in Swift, I developed to speed up my development process.


Read More...
How To: Support User Editable Python Macros In A I Os Application

Last month I published a article on how to use JavascriptCore for extending a iOS application with macro support. While Javascript has many uses, as a way for application customization, it would not be my first choice.

A better choice to me would be a language like Python. Being curious, I wondered what it would take to to use Python. This article discusses what I found.


Read More...
How To Example: Extend A I Os Using Javascript Core As A Macro Engine

JavascriptCore is a framework that offers the ability for a iOS application to interact with javascript code. Primarily used for cross platform code sharing, it can also be used to extend a iOS application with macro capabilities. This framework offers a world of possibilities for extending any iOS application.


Read More...
How To: Custom I Os Activity Tracker View Using Ca Layers

The Apple Watch shipped with a captivating activity tracker. The center piece is a really cool spiral animation scheme showing the amount of activity during the day. This image is also shown on the matching iPhone Activity App. I have always wanted to see what it would take to implement this myself. The examples that I see typically use a custom drawRect override, but I always wanted to see what it would take to do with CAShapeLayers.

Implementing a 0-100% control is straight forward when using CAShapeLayer. But how do you implement a progress indicator that support progress values greater then 100%? This How To discusses a solution that I came up with along with it’s potential limitations.


Read More...
How To Display Custom Content On A External Screen From A I Os Device

Being able to display content on a external screen or device is a great capability to add to a iOS application. Especially how easy it is. This article will show the step required to to do this.


Read More...

Follow us on

Articles by published month

Articles by subject matter

Rails Thor Compass Susy Modernizr Rspec Capybara Bettererrors Railspanel Aws Rack Railscasts Http Aws-elastic-beanstalk Ruby-on-rails Rack-rewrite Http-response-codes Pow-amazon-route-53 Stackcalc Iphone Ios Mobile Application Skeumorphic Dns Web-site Elastic-beanstalk Elastic-ip Elastic-load-balancer Tutorial Howto Javascript Javascriptcore Macro Example Swift Design-patterns Observer Python Macros Alamofire External-screen-support Apple-watch Activity-tracker Office Status S100 Cloud Astronomy Picture Mars Apple Usb-c Leonard-nimoy William-shatner Geotag Gps Spztracker Geotagging Photos Secret Marketing Watch Watch-repair Head-transplants Perception Diabeties Sugar Health Rosette-nebula News Spock Comet-lovejoy

Click here to receive free tips and tutorials!

This web site uses javascript exclusively for automating html elements. Please enable javascript to fully experience the features offered on this site.