I am available for freelance work! Click here to email me.

Bort – A Base Rails Application

September 9th, 2008

An Introduction

When I set up a new rails app, I generally do the same things every time. Set up a config file, install RESTful authentication, add password recovery stuff, blah blah. I’m sick of doing the same stuff over and over again. Enter Bort.

Bort is a base application featuring all the things I set up with every application. Now I can just download the app from git and be up and running within a matter of minutes. POW!

For those of you wondering is Bort stands for anything like “Bionic Optical Radioactive Trout”, it doesn’t. It’s taken from this episode of The Simpsons:

Anyway, enough of this piffle, on to the features:

The Features

I’m going to copy and paste this jazz from the readme file because, quite frankly, I’m lazy.

RESTful Authentication

RESTful Authentication is already setup. The routes are setup, along with the mailers and observers. Forgotten password comes setup, so you donít have to mess around setting it up with every project.

The AASM plugin comes pre-installed. RESTful Authentication is also setup to use user activation.

Will Paginate

We use will_paginate in pretty much every project we use, so Bort comes with it pre-installed.

Rspec & Rspec-rails

You should be testing your code, so Bort comes with Rspec and Rspec-rails already installed so youíre ready to roll.

Exception Notifier

You donít want your applications to crash and burn so Exception Notifier is already installed to let you know when everything goes to shit.

Asset Packager

Packages up your css/javascript so youíre not sending 143 files down to the user at the same time. Reduces load times and saves you bandwidth.

Routes

The routes for RESful Auth and the forgot password stuff are already sorted for you.

Settings YAML

There is a settings.yml file that contains site-wide stuff. The site name, url and admin email are all used in the RESTful Auth mailers, so you donít need to worry about editing them.

Database YAML

The database.yml defaults to sqlite3 but also contains the settings for MySQL in comments so you can switch over easily.

Capistrano Recipe

Bort comes ready to rock capistrano. The recipe that is setup is based on using git and passenger. Edit as you see fit.

Uses the Database for Sessions

Bort is setup to use the database to store sessions by default.

Misc
  • password and password_confirmation are set up to be filtered
  • there is a default application layout file
  • a page title helper has been added
  • index.html is already deleted
  • rails.png is already deleted
  • a few changes have been made to the default views

Using Bort

The git repo is located here: http://github.com/fudgestudios/bort/tree/master

  • Download and unzip Bort
  • Edit the database.yml and the settings.yml files
  • Rake db:migrate
  • Have a brew and celebrate

Suggestions etc

If you have any suggestions about things we should add, edit, delete from Bort then let me know. Think we should gemify it? You decide.

(Possibly) Related Posts

Recommend Me

If you found this post or anything else on this site of any use, then please take the time to recommend me on Working with Rails.

You can follow any responses to this entry through the RSS 2.0 feed. Trackback from your own site.

  • Sami
    I am relatively new to rails, and would love to be able to give bort a try. I'm having an issue running rake db:migrate. I ran rake --tasks, and I don't see db:migrate on the list. Here is the errors. Please help with any suggestions where to look or what might the problem be. Thanks.

    >rake db:migrate
    rake db:migrate
    (in /Projects/rails_projects/bortApp/vendor/plugins/restful_authentication)
    rake aborted!
    Don't know how to build task 'db:migrate'

    (See full trace by running task with --trace)


    >rake db:migrate --trace
    rake db:migrate --trace
    (in /Projects/rails_projects/bortApp/vendor/plugins/restful_authentication)
    rake aborted!
    Don't know how to build task 'db:migrate'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:1704:in `[]'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:2026:in `invoke_task'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in `top_level'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in `each'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in `top_level'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in `standard_exception_handling'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:1999:in `top_level'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:1977:in `run'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in `standard_exception_handling'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake.rb:1974:in `run'
    /Library/Ruby/Gems/1.8/gems/rake-0.8.4/bin/rake:31
    /usr/bin/rake:19:in `load'
    /usr/bin/rake:19

    >rake --tasks
    rake --tasks
    (in /Projects/rails_projects/bortApp/vendor/plugins/restful_authentication)
    rake clobber_rdoc # Remove rdoc products
    rake default # Default: run unit tests.
    rake rdoc # Build the rdoc HTML Files
    rake rerdoc # Force a rebuild of the RDOC files
    rake test # Run tests
    >
  • Jason
    If you follow the instructions to upgrade to rspec-rails 1.2.2 and rspec 1.2.2 and then upgrade bort using this (http://wiki.github.com/dchelimsky/rspec/configgem-for-rails) it is then possible to run rake rspec and command line without any problems. This addresses the problems noted in the config/environment.rb with the commented rspec gems.

    Now to update tests to be consistent with the rspec 1.2.2 version to get the specs to pass.
  • Jason
    Interesting. The gems appear to be frozen with the release, but I have rspec-rails 1.2.2 installed as a gem and somehow the rake spec target is invoking code from the gem repository rather than the vendor/gems directory.
  • Jason
    I might be missing something.

    Ran rake spec and I'm getting an 'alias_method': undefined method 'failure_message_for_should' for class 'Spec::Matchers::Have' (NameError).

    When I run each test (inside TextMate) I get the same route errors as John.

    Thoughts?
  • Mustafa
    it seems like bort does not work with rails 2.3.2 due to the open id plugin. and I always think that open id is something to be excluded from bort since it is not a default for any project.
  • John
    I'm getting some problems with routes in the tests

    Using Autotest I get these failures

    1)
    Test::Unit::AssertionFailedError in 'UsersController route generation should route users's 'update' action correctly'
    The recognized options "show", "id"=>"1", "controller"=>"users"}> did not match "update", "id"=>"1", "controller"=>"users"}>, difference: "update"}>
    ./spec/controllers/users_controller_spec.rb:114:

    2)
    Test::Unit::AssertionFailedError in 'UsersController route generation should route users's 'destroy' action correctly'
    The recognized options "show", "id"=>"1", "controller"=>"users"}> did not match "destroy", "id"=>"1", "controller"=>"users"}>, difference: "destroy"}>
    ./spec/controllers/users_controller_spec.rb:118:

    3)
    Test::Unit::AssertionFailedError in 'SessionsController route generation should route the create sessions correctly'
    The recognized options "show", "controller"=>"sessions"}> did not match "create", "controller"=>"sessions"}>, difference: "create"}>
    ./spec/controllers/sessions_controller_spec.rb:104:


    running ./spec gives me these

    1)
    Test::Unit::AssertionFailedError in 'SessionsController route generation should route the create sessions correctly'
    The recognized options "show", "controller"=>"sessions"}> did not match "create", "controller"=>"sessions"}>, difference: "create"}>
    /home/john/Rails/fudgestudios-bort-298ef7375287c752a49d9f5728088f7e67958c6f/spec/controllers/sessions_controller_spec.rb:104:

    2)
    Test::Unit::AssertionFailedError in 'UsersController route generation should route users's 'update' action correctly'
    The recognized options "show", "id"=>"1", "controller"=>"users"}> did not match "update", "id"=>"1", "controller"=>"users"}>, difference: "update"}>
    /home/john/Rails/fudgestudios-bort-298ef7375287c752a49d9f5728088f7e67958c6f/spec/controllers/users_controller_spec.rb:114:

    3)
    Test::Unit::AssertionFailedError in 'UsersController route generation should route users's 'destroy' action correctly'
    The recognized options "show", "id"=>"1", "controller"=>"users"}> did not match "destroy", "id"=>"1", "controller"=>"users"}>, difference: "destroy"}>
    /home/john/Rails/fudgestudios-bort-298ef7375287c752a49d9f5728088f7e67958c6f/spec/controllers/users_controller_spec.rb:118:


    I'm on Rails 2.2.2, oh yeah and I don't *really* know what I'm doing.

    I'd be chuffed if someone could tell me where I'm being stupid.
  • Loving it! Newbie, and finally got it running through deployment to another site!
    Now I need to add an application (hahaha!).
    What should I read to understand how to use this (since you don't have a stub application to replace)? (I.e., which plugin to search on to understand how to use it.)
    Again, thank-you.
  • Awesome. Just started my second rails project and it sped things up dramatically! No kinks either.
  • Bob Calco
    OK I figured out what my problem was. I'm using a non-standard database adapter on win32... Sam Smoot's mssqlclient. I have been massaging it to work on Rails 2.2 with some success but I occasionally find some odd stuff going on. In this case, it's prepending default strings with "N". In SQL Server you usually write something like N'somestring'. Apparently it's concatenating the N and the string. So for example, the 'name' attribute of user, which defaults to '', is "N". I can fix this. Changing the user.state to "passive" (instead of Npassive) and then calling user.register! an user.activate! did the trick.

    - Bob
  • Bob Calco
    I'm running into a problem during the migration when user.register! is called... deep in the bowels of aasm.rb, the call on line 118 to aasm_state_object_for_state(aasm_current_state) is returning nil, so rake db:migrate fails when it tries to call nil.call_action(:enter, self).

    I took the creation of the admin role and initial admin user out of the migration (or rather, commented it out). After I successfully ran the migration without those steps, I manually reproduced them in the console.

    I was able to create the admin role and the user, and add the admin role to the user. But calls to both user.register! and user.activate! yield the following error:

    MethodError: You have a nil object when you didn't expect it!
    The error occurred while evaluating nil.call_action
    from /vendor/gems/rubyist-aasm-2.0.2/lib/aasm.rb:118:in 'aasm_fire_event'
    from /vendor/gems/rubyist-aasm-2.0.2/lib/aasm.rb:56:in 'register!'
    from (irb):8

    (substitute 'register!' with 'activate!' when I call user.activate! in above trace.)

    I am running Rails 2.2.2, not 2.2.0.

    - Bob
  • Thanks Adam, I'll get that fix committed. :)
  • I was able to fix the error `rake aborted! no such file to load ó spec/rake/spectask` by changing line 7 of lib/tasks/rspec.task to:

    rspec_base = File.expand_path(File.dirname(__FILE__) + '/../../vendor/gems/rspec-1.1.11/lib')
  • I'm getting the same error as Douglas above. OSX 10.5, Rails 2.2
  • Douglas
    When I run `rake db:migrate` I get the following error...
    `rake aborted! no such file to load -- spec/rake/spectask`. What gives? I am on Windows XP, Rails 2.2.
  • Philip Rhoades
    Don't worry - I worked this out . .

    Thanks,

    Phil.
  • Philip Rhoades
    srb,

    Thanks - I did work that out eventually . .

    Next question relating to authentication - for a library app (books, CDs, DVDs) I want to use the Rails dir:

    pricom.com.au/library

    and I have started using Passenger (mod_rails) - I had to hard code "library" into paths in layout files so "authors", "books" etc can be found (eg /library/books) because RailsBaseURI doesn't seem to work past the base name. Anyway, activation emails are being sent out without the "library" eg with a URL of:

    http://pricom.com.au/activate/b4cd0. . .

    Where do I hard code "library" to fix the URL?

    Thanks,

    Phil.
  • srb
    Phillip,

    Why are you copying this line?
    skip_before_filter :verify_authenticity_token, :only => :create

    You probably want this instead:
    before_filter :login_required
  • Bort is really handy, but I feel that with the introduction of open ID support you may have gone a little too far in one direction. None of my projects ever use open id, for a variety of reasons. Hopefully you won't get caught up in adding too many more features at the base, as the last thing a cool time-saving project like this needs is feature bloat. Either way, thanks for making this!
  • Philip Rhoades
    I have bort working in isolation but when I create a new table "dummy" with:
    script/generate scaffold Dummy status:string lastname:string firstname:string email:string phone:string description:text
    run:
    rake db:migrate
    and then copy the line:
    skip_before_filter :verify_authenticity_token, :only => :create
    from the sessions_controller.rb file to the dummies_controller.rb file and then viewing:
    http://localhost:3000/dummies
    does not display the login page . . what am I not doing/doing wrong?

    Thanks,
    Phil.
  • This application is Great! :)
    Thanks for the stuff and guidelines...
  • mario
    thank you! a huge timesaver.
  • Bill Gathen
  • Bill Gathen
    Worked fine in Mongrel, but when I tried it under Passenger I kept getting the server root url after logging in/out.

    Changing all occurrences of "redirect_back_or_default('/')" to "redirect_back_or_default(root_url)" got me going again. There are 2 in sessions_controller.rb and 3 in users_controller.rb.

    Otherwise, great setup. Thanks!
  • Kevin
    Hi,

    I notice the default routes have been removed from routes.rb.
    It seems that not having them breaks the reset password stuff here:
    { :action => 'update_after_forgetting' } do |f| %>

    We get a missing route error.
  • tanel
    What about log rotating?
  • Thanks for RoleRequirement! ;)
  • srb
    Doh!

    There are plenty of Rspec tests.

    The only thing I would change in it as a default base app is to change the landing page after signup/login to something else and just make it a replace me page with instructions on changing the route.

    I think the real value add once the all the setup is up is to document everything - particularly where to go after successful setup - ie- how to add your models, where to put the restful security, how to use the various installed plugins, etc...
  • srb
    How about tests?
  • @Ben - will include it in the next release which should be sorted y the start of next week :)
  • That should be "fixtures," not "features"
  • Jim this is awesome. The only change I've made so far is to move the REST_AUTH_SITE_KEY from config/initializers/site_keys.rb to config/environments/*.rb so that I can make my own key for development and production without breaking the included features. Thanks a bunch!
  • Tim Haines
    Nice! Great to see you take the time to do this. What about paperclip, swfupload, rvideo, and ffmpeg? ;-)

    Tim.
  • exception notifier out, hoptoadapp.com in
    asset packer out, bundle fu in

    apart from that i agree :)
  • The settings is actually the config.yml file. I should probably edit this post to reflect that.

    For the email settings, I'll add that some time this week.
  • I just downloaded this bundle and got it running in no time. I do have 2 questions:
    like @Fred mentioned above, I don't see the settings.yml file, I do see in the config directory a config.yml. A second question is where do I put the config settings for my outgoing mail server? I want to send mails via my company's smtp server?
    Thanks!
  • Brandon
    Great idea! I loved that episode!

    ...
    Guy on PA: Attention Marge Simpson! Your son has been arrested!
    Woman in store: Oh I'd hate to be that boy's mother.
    Guy on PA: Attention Marge Simpson! We've also arrested your older, balder, fatter son!
    ...
    Marge: I wish there was a hole I could crawl into and die.
    German Guards: OK! Throw her in de hole!
  • Matt
    @Oleg: Using AssetPackager isn't a requirement for Bort - if you feel happy using the packager in rails, then fair enough - it'll still work.

    @Jim: Ta for the link.
  • Why not make it a generator like the rails command?
  • Ashley Williams
    If you were this popular at school, maybe Bort wouldn't exist!

    Very cool, going to use Bort for my next project! (I hope you keep it updated with the latest stable Rails!)

    Thanks!
  • Adam
    Thanks, it's a good resource to have. I've been baseing my projects off of Goldberg up till now.
  • Fred
    I'm not seeing the setting.yml file.
  • We've got 38 watchers for Bort on github. I wish I was that popular at school!
  • Oleg
    @Matt - Does whitespace and comments really make such a big difference to warrant use of AssetPackager, especially when you should be sending content gzipped anyway? AssetPackager made sense pre Rails 2.0, now I just don't see the point.
  • @Matt - Added a link to your fork, yeah?
  • Matt
    There is also a version of bort with email / password authentication instead of the traditional username / password combo - just for those of us that prefer using email addresses instead of usernames. More details here:

    http://matthall.wordpress.com/2008/09/09/a-bort-fork-rails-base-application/
  • @Oleg - See Matt's comments.

    @Daryl - OpenID stuff is one of the thing's I've been thinking of adding to the mix. I'll look into tomorrow.
  • I'd also suggest open__id_authentication as well. I end up integrating this all the time now.

    Very cool idea just cloning now and will check it out.
  • Matt
    @Oleg: Asset packager removes whitespace and comments from your files, reducing the total file size. The javascript_include_tag method keeps all whitespace and comments, which makes for better readability, but as we're using Bort on high-traffic sites, we need to be concious of the size of files being sent over the wire.
  • That's awesome. Totally fitting my lazy copy and paste work style for new projects, hehe! And I like the name too. Will definitely start my next app with this. Thanks mayn!
  • Oleg
    What the point of using AssetPackager is you can do something like this: javascript_include_tag :all, :cache => true Same applies to css.
  • Matt Hussein Platte
    This should be in Rails core.
  • Martin
    How easy would it be to remove rspec and rspec rails to use shoulda instead
  • Adam
    I tried to do this once. I failed. I'm glad to see you succeeded, thanks!
  • RoleRequirement (http://code.google.com/p/rolerequirement/) is another interesting piece of rails plugins. And works like Restful Authentication.
  • Wow, what a great idea, I will give this a try and see if I can make it work! (All of 2 weeks RoR experience so far!) ;)
  • Haha that's some legacy stuff from internal work.

    I'm going to update the github page tonight/tomorrow as some stuff has changed since it was set up.
  • Nate
    How about changing the description of Bort to something that can be found through searching on github? "Chester says Bort, yeah?" wasn't the first thing I thought to search on, you know? ;)
blog comments powered by Disqus
Purify - Issue Tracker

Jim Neath is a 26 year old Freelance Ruby on Rails developer from Manchester, UK.

Recommend Me

Categories