Sprint 0 Completed!
April 6th, 2008
Tonight I finished Sprint 0 on the Ruby on Rails Blog Starter Kit. It’s not much, but it’s starting to take shape. In this sprint I implemented the following features:
- Show 10 most recent posts on home page
- Show a single post
- Allow an admin to login using an OpenId
- Allow an admin to create posts
- Allow an admin to edit posts
- Allow an admin to delete posts
- Design
There are still many, many refinements to be made across the board, but the initial work is done.
This coming week will mark the beginning of Sprint 1. The features targeted for Sprint 1 are:
- Allow comments for post
- Akismet integration
- RSS/Atom Feeds
- Tagging Posts
- Textile Integration
- Design enhancements
These are some pretty big features, but I believe I should be able to tackle them for this sprint. I’m fairly excited about most of them, especially Akismet and Textile integration. Akismet is something I’ve wanted to play with for some time now, just to see how it’s setup & how it works. Textile will be nice because it’s going to make my posts look pretty!
Featured Code Snippet
For this sprint, I have one piece of code that I’m particularly proud of. It stems from the need to render (or do) something different based on the user’s authentication/authorization status. For example, if the user is not logged in, do not give them access to this action. Or, if the user is not an admin, show them this view, otherwise show them a different view. I accomplished this by adding two methods to my application controller: the first deals with authentication, the second with authorization. Let’s take a look:
def for_admin_only
unless @current_user
redirect_to(root_url)
else
yield
end
end
def for_users_by_type
if @current_user
yield :admin
else
yield :anonymous
end
end
These methods are consumed by the controller like so:
for_admin_only do
render :html => @posts
end
for_users_by_type do |type|
case type
when :anonymous
render :html => @posts
when :admin
render :template => 'admin/posts/index', :html => @posts
end
end
In the second snippet, we call for_admin_only first, which says that if the user is logged in, then run the specified snippet of code, otherwise redirect to the homepage (this could also redirect to a 403 page, or whatever else you prefer). Next, we call for_users_by_type, which passes back a type variable saying if the user is anonymous or admin. If the user is anonymous we render the basic view, if s/he’s an admin, we render the admin index view.
So head on over to the official github repository and check out the source! It’s very pretty! (EDIT: Also, you may see a summary of these details on the project wiki)
- Posted 4 months ago
- comments[0]
- Permalink
- Digg This!