Why we don't use a Rails template
thunderboltlabs.com
thunderboltlabs.com
No, it's not. Manual effort is being automated. That manual effort includes calling to remembrance a list of gems, looking up their installation instructions on GitHub, modifying views, editing initializers, converting ERB files to Haml, setting up your test environment just so, and whatever else floats your boat. Assuming a team can agree on some sensible defaults, it can save significant amounts of time to have all those steps automated each time you want to spin up a new project.
"The technical and social friction in changing the template discourages evolution."
No, it doesn't. There is nothing stopping me from deviating from the norm once the application is generated. Or if I need to preempt a step in the generator, I just 'gem unpack' the generator, make my tweak, 'rake install', and generate from that. If it works out, I can push the change up in a branch and submit a pull request. The team can discuss.
Automation is good. From a business perspective I believe it's codifying your expertise. Clients benefit from that automation, because you spend 10 minutes spinning up their project instead of 2-8 hours recreating pretty much the same wheel you created last month.
It really depends on whether or not you start a lot of new projects. If you're a Rails dev shop that does a wide variety of apps on a regular basis, then the N=1 cost of maintaining the template is well worth the per-project getting-started cost.
https://github.com/metaskills/holy_grail_harness
I can see both sides of the argument here. My application prototype is really slim and focuses on bootstrapping an application with a major emphasis on testing tools. Even tho it has a JavaScript MVC framework (Spine.JS) it will remove all traces depending on your setup questions. This approach to a lean prototype means it can easily be updated like a normal Rails application and changed/forked as needed. Best of both worlds hopefully.
I also think that a great use case for templates is to try out new gems before deciding on whether or not you'd like to use them.
Love it.
The tl;dr here is that almost all of the decisions that an app template makes are decisions the team should be discussing. Otherwise, the homogeny of an app template creates a "you're doing it wrong" cargo-culting attitude.
Great post. Glad I read this.
Err, that's a Rails Temple, sorry.
The OP argues against using a "Rails template" but ultimately his argument is against using a starter app to begin a Rails project. His concerns are reasonable but ultimately shortsighted.
You see, everyone uses a starter app. Here's your choices:
1) Use "rails new" to get the default Rails starter app. Add your favorite gems and tweak everything to work together.
2) Build a starter app with you favorite gems, store it in a repo, and make a copy every time you start a new project (search and replace to change the app name in ten locations).
3) Build a gem that copies a starter app with all your favorite gems. Build in a search-and-replace script that changes the app name.
4) Build an application template that generates a starter app using "rails new -m".
#2 is faster than #1 for starting up a project (except for a little time to copy the starter app to a repo) if you are using the same starter app more than once.
#3 and #4 are faster that #1 and #2 for starting up a project but more time is required to "build the tool." Fine if you can save more time running the tool than hand-assembling as in choice #1.
But there's a problem with #1, #2, #3, #4. All starter apps are time consuming because you need to take time to figure out what's changed since you last used your favorite gems and hunt down any new tweaks needed to get your favorite gems to work together. Most developers underestimate this effort and and most starter apps, application-generating gems, or application templates end up mired in the tar pits of neglect, abandoned in the constant change of Rails and its gem ecosystem.
There's another choice:
5) Participate in an open source project to maintain a set of starter apps with commonly used gems. Since you are always going to use a starter app (of some kind), why not use one that other developers are using? And benefit from a community effort to identify and patch integration issues.
That seems to be what's driving the popularity of the RailsApps project (800+ "stars" and 150+ forks on GitHub for the rails_apps_composer gem). Here's the link:
Now about what the OP said:
"Even after the first implementation, the template must be constantly tweaked and finagled to keep it up to date."
Yep, that's where you need the leverage of a community supporting an open source project.
"Each one of the decisions that the template makes for you should be discussions within the team."
There's no reason to have a single starter app or template that generates only one stack. Take a look at the RailsApps repo. You'll find starter apps that use MongoDB, others use SQL. The Rails Composer application template will give you a choice of ERB/Haml/Slim, Twitter Bootstrap or Zurb Foundation, PostgreSQL/MySQL/MongoDB, RSpec/MiniTest, OmniAuth/Devise, etc., etc. Have your team discussion; find out what the larger community is saying; make informed choices. You can have multiple starter apps and choose the one that is appropriate for the project at hand.
"The fact is, 'best practices' are a moving target. They evolve through team communication and cohesion."
Yep, and if your team participates in an open source project to build and maintain useful starter apps, you'll benefit from the efforts of a larger community and contribute to the growth and wider adoption of Rails.
I love being able to always know that when I want to create a new app, I have my core gems - that will always be up-to-date once I run the RailsApps generator.
One of the best tools in my toolbox as a Rails dev.
Thanks Daniel for all your awesome work.
At the same time, I do agree with many of the points in Tammer's article. I think the danger with Rails templates, scaffolding and even Daniel's work is that it's very easy to take it and use it part and parcel without understanding what's really going on inside, and why certain decisions were made (this gem vs. that gem, or this code technique vs. that). I think there's a lot of value in starting from scratch (Daniel's option #1) and adding things step by step. As Tammer pointed out, this can lead to a positive team discussion and learning dynamic. And I don't mind the extra typing and time required.
The next time I start a new Rails app, I'll probably: - Look for a good example to learn from in RailsApps or elsewhere. - But then step back to "rails new" and add in the recommended gems bit by bit, with testing along the way. - Hopefully contribute back to RailsApp if I learn anything new :)