Tag: templates
Introducing ActiveRecord Skeleton
by Christoph Olszowka on Feb.21, 2009, under ruby
It’s common knowledge that ActiveRecord can be used nicely without Rails in Ruby apps. Setting up the basic stuff is pretty easy by just requiring the activerecord gem in your app and defining a couple of models.
But what about migrations, yaml config and different environments? You have to set all this up manually, and even though this is not really hard, it’s still a time-consuming task. No more!
Enter: ActiveRecord Skeleton
I published a new project on GitHub today, called ActiveRecord Skeleton, and it really is just that: It will instantly give you YAML db config, database migrations (including Rake tasks for migrating the database as well as generating new migrations), a Rails-style project directory structure, and also the option of using environments by specifying the RACK_ENV environment variable. Why RACK_ENV? Well, you might also see this as a super-minimalist web app template, allowing you to set up a db-backed Sinatra (just an example, anything should work really) app instantly. All you really got to do is get the skeleton and add an application.rb file containing the following:
require 'sinatra'
require 'init'
get '/' do
User.all.map {|u| u.name}.to_sentence
end
After running application.rb and pointing your browser to localhost:4567, you will see the list of existing users (assuming you’ve got the database and model set up properly, of course).
Want to create a user? Start irb, do a require 'init' followed by User.create.
This skeleton is really minimalist, as I didn’t want it to be over-opinionated. It’s meant to give an easy start for about any Ruby code you might want to have database-interaction with and is ready to go with sqlite 3 in the default setup, but you really can use it with any database ActiveRecord supports.
As a consequence of the minimalist approach, the skeleton does not supply tasks or folders for tests. The reason for this is simply that I did not want to force users of the skeleton into using a certain testing library. Test::Unit, Shoulda, RSpec, (your favorite testing framework mentioned here), just pick your favorite and add it your project. This is by no means a suggestion to ditch testing altogether though. You’re just supposed to pick your flavour of TDD or BDD.
Now head over to GitHub and give it a spin!
Ruby / Rails related links
by Christoph Olszowka on Jan.24, 2009, under rails, ruby
Sinatra app template
Nick Plante has released a nice application template for Sinatra, with a reasonable initial directory structure and a Rackup script for easy use with Passenger. Haml, DataMapper, RSpec and such are also included, so this is pretty biased, but you’re free to fork it and adjust to your needs on github
I gave it a spin and had no problem to run it with Passenger by just pointing the Apache vhost configuration to the public folder of the app, so this is also great when you’d like to have an example on using Rack apps with Passenger.
Rails templates
Application templates seem to be up and coming currently, with the best thing obviously being the Rails templates feature in Edge Rails a.k.a. the upcoming Rails 2.3. Core member Pratik Naik posted a nice summary of the available methods in December, and Peter Cooper from Rails Inside posted more on the topic yesterday, with links to example scripts.
Basically this allows for scripting of the Rails application generator, giving you a DSL with methods to pull in plugins, executing rake tasks and so on. The template can be pulled in remotely, for example from a gist. Peter “Super Daring App Template” can be used with rails [whatever] -m http://gist.github.com/33337.txt, and you are free to fork it and roll your own.
Some kind of template database would be nice though, listing all public templates and their features, so you can pick your favorite and use it.
Zebra – One line tests for shoulda, context and matchy
I really like Shoulda. James Golick has released a gem that enhances it further, called Zebra.
The functionality can be summed up with this example from James’ initial post:
should "be editable by its author" do
assert @post.editable_by?(@author)
end
becomes…
expect { @post.to be_editable_by(@author) }
Roll your own Pastebin with NavySnip
NavySnip is a pastie pastebin Rails application, but intended for localhost use. Check out the screenshot or have a look at the github repository.
Currently, it does not have syntax highlighting, but with a little help from Coderay or a similar Ruby gem, it should be easy to bring that into the app.
Free Lighthouse/Basecamp-inspired web app theme
Andrea Franz released a nice-looking web app theme that looks very familiar if you have been to sites like Lighthouse or Basecamp. Go check it out at Github and make a great app with it!
Little Known Ways to Ruby Mastery by Ryan Bates
To finish things up, there is a nice interview with Ryan Bates over at Rubylearning






