#148 App Templates in Rails 2.3
In Rails 2.3 you can provide a template when generating a new Rails application. See how in this episode.
- Download:
- source codeProject Files in Zip (1.56 KB)
- mp4Full Size H.264 Video (19.7 MB)
- m4vSmaller H.264 Video (12.6 MB)
- webmFull Size VP8 Video (33.2 MB)
- ogvFull Size Theora Video (27 MB)
This might just turn out to be insanely useful. The other day I started a fresh Rails app and realized just how many settings I were fiddling around with.. didn't feel very Rails like.
Scripts on Github, writing a function in the bash file.. great advice.
Many thanks Ryan !!!!
I'm really impressed by the possibilities which these templates are providing to us.
I agree with Jamie, because customizing the app after running the rails command takes sometimes very long and could be now easily speedup.
great screencast!
I don't know, I just don't find this any more useful than keeping "templates" in Subversion (or git).
I have several project templates under version control and clone new projects off those.
For some reason, the MOV file stops halfway through for me. Anybody else have that problem?
Hello Ryan,
Ruby's output delimiter %q provides a concise alternative of here documents, especially when you have a few lines of code. You can see an example here:
http://gist.github.com/60801
Thanks again!
Michelangelo, you'd save another character if you dropped the "q" ;)
Heredocs can offer a different kind of concision, though: http://gist.github.com/60823
I also experienced the movie getting cut off in the middle, at the height of the suspense. I was sooo engrossed. Ryan, Great movie. Please, can't we see the rest?
Awesome screencast Ryan! I'm really glad you did this one now since I can see some great uses for app templates. I didn't have any problems with the video on Linux using mplayer.
@jeroen: One disadvantage of your solution is, that your "templates" do include one specific version of rails and included gems & plugins (Updating rails doesn't update all files in your app. E.g. the config/environment.rb or the config/initializers/* are only generated for new apps).
Also you can't use functions like ask or yes? nor can your "templates" inherit from other templates.
@Andy, @Yitzhak interesting, it is downloading all the way for me. Try right-clicking the link and choosing download instead of having it load in the browser. You may also want to try the alternative format (for iPod).
Curious about applying templates to existing apps, as I'll be doing it a lot. Will everything behave gracefully?
Using the following
http://pastie.org/385727
git :commit is executed before git :add.
Anyone know why? I'll try to break it into two lines but I just thought it was weird.
@cbmeeks: This is probably because Ruby < 1.9 does not keep insertion order on hashes:
irb(main):002:0> {:add => ".", :commit => "-m 'foo'"}
=> {:commit=>"-m 'foo'", :add=>"."}
Thus, the commit command will be executed first, even though you gave it as the "second" argument. I don't know about the inner workings of the git method in the Rails Templates, but probably it's just a plain "def git(options)", so the arguments you provide become a plain hash with mentioned problem.
@Ryan: I think there is an issue with using both git commit and rake gems:install, since the former will use your git credentials specified in your user config, while the latter will need sudo rights.
Executing the whole script as sudo will let gems install, but will probably give you empty git committer names (as long as you do not have them specified for root as well) and of course root permissions on all your apps files.
I found a nice detail in Peter Coopers example template (see http://gist.github.com/33337), which executes gems:install with the additional :sudo option:
rake('gems:install', :sudo => true)
Thanks for another great tutorial Ryan!
I like the new feature, thanks you!
If anyone has troubles installing Rails 2.3.0 RC1, you may need to install Rack first:
sudo gem install rack
@Christoph Olszowka
I bet you're right! That makes sense.
I do have Ruby 1.9 installed but I can't seem to get any gems to work with it. I'm running Rails 2.3 just fine. But I had to run it with Thin and not webrick because each request was taking 40 seconds...but I digress... :-)
@RyanB
I had to add "include Authentication" in the application_controller after following your example. No biggie. I might have messed up but anyway, just FYI.
BTW, you rock dude!
~cbmeeks
Great screencast, Ryan. Good job.
Really Nice Article. Great Job.
so are these new App Templates going to replace the Base Rails Apps floating around out there (eg bort, blank, etc)?...or does this new feature serve a totally different purpose? Can someone please explain? sorry, for the noob question. thanks!
This is great! Thanks for the heads up on this functionality. This has helped me with opening the flood gates of creative ideas.
Please keep up the great work.
I can't seem to get rails to use the template from github.
It just sits at "applying template: http://github..."
and eventually times out. Can anyone help?
Thanks for another great screencast Ryan.
A lot of plugins require you to edit various files for installation. For example, the rails-authorization-plugin requires you to add some stuff to environment.rb.
restful authentication requires you to add include AuthenticatedSystem to your application_controller.
Is there a good way to handle this?
I recently made an awesome Rails Template that emulates what Bort and some other people have done. Check it out at:
http://github.com/schmidtjra/Rails-Templates/tree/master
@Robert Matei
You can apply templates to existing apps using rake:
rake rails:template LOCATION=/path/to/template.rb
You may want to ignore stuff like .DS_Store in a global .gitignore file rather than your project's .gitignore file simply because there's never a case in any type of project where that should be checked into source control.
Use the global core.excludesfile configuration variable for this, and just set it to ~/.gitignore.
Hi Ryan,
great screecast as usual.
I am trying to include my template from my git repository as you suggested.
I run
rails new AppName -m urltogitrepo
It does create skeleton of my app by fails to locate template. I can see it's prefix url with my current path.
Is it related to Rails3 or me doing it on windows?
Thanks
Thanks, Ryan. This is still a great intro to rails templates about 3.5 years after you originally "cast" it. I'm using rails 3.2 and found that the
load_template
you use to load the base.rb into authentication.rb is depreciated. The current Thor equivalent isapply
. That might be useful to your more recent users.Best,
Ben