Recently Mozilla Labs released a prototype of snowl, a rss/atom/twitter feed reader. It is a firefox plugin and provides two views of messages — a “traditional” message view, as well as a “river of news“. I thought that this could be easily “redone” as a rails application. The rest of this article steps through the process of creating it.
So what’s O_RLY all about?
Well, the name snowl struck me as being a merger of two words, “snow” and “owl”. So, a quick google on snow owl, and it led me to the Wikipedia entry for “Snowy Owl”, which then referenced “o_rly“. The image associated with “o_rly” is that of a snowy owl:
So….. The name was set.
Next on to the creation of the app…
Programming O_RLY
I’m assuming rails 2.1.0 as well as an up-to-date installation of rubygems.
The basics: RubyGems, testing, and Restful Authentication setup
- First create the rails project:
rails o_rly
. By default it uses sqlite. - Next, install the following gems:
- FeedNormalizer — This makes reading rss/atom feeds easy.
1sudo gem install FeedNormalizer - Twitter — For doing twittery things, of course.
1sudo gem install twitter
- FeedNormalizer — This makes reading rss/atom feeds easy.
- Plugins next:
- I’m using rspec for testing, so I need to do the following to install it for rails:
123script/plugin install git://github.com/dchelimsky/rspec.gitscript/plugin install git://github.com/dchelimsky/rspec-rails.gitscript/generate rspec - acts_as_state_machine — This is used by Restful Authentication for user creation.
1script/plugin install http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk acts_as_state_machine - Restful Authentication – This allows us to easily work with users.
1script/plugin install git://github.com/technoweenie/restful-authentication.git
We also need to run it’s generator. I am running it to set up authentication required.
1script/generate authenticated user sessions --include-activation --stateful --rspec
Run its migration
1rake db:migrate
If you are running autotest (which is a good idea), now would be a good time to create your test database as well.
1rake db:migrate RAILS_ENV=test
- I’m using rspec for testing, so I need to do the following to install it for rails:
- Configuration
- As of 12 Aug, 2008, there’s an issue with rails and restful_authentication. To resolve this, according to Luca Guidi you need to make sure that the following lines are in
vendor/plugins/restful_authentication/init.rb
:
12require File.dirname(__FILE__) + '/lib/authorization'require File.dirname(__FILE__) + '/lib/authorization/stateful_roles'
I found that I was missing the second, but the first was there. - According the the restful authentication wiki, we need to add the following to
config/routes.rb
1map.activate '/activate/:activation_code', :controller => 'users', :action => 'activate', :activation_code => nil
Additionally the resource mapping for users (map.resources :users
) needs to be changed to
123map.resources :users, :member => { :suspend => :put,:unsuspend =>; :put,:purge =>; :delete } - Next we need to add an observer to
config/environment.rb
(look for the section labeled observers).
1config.active_record.observers = :user_observer - In order to make things easier for development, we’ll take a note from avnet lab’s Restful Authentication with rails 2 and edit
config/environments/development.rb
to add the following line:
1SITE_URL='localhost:3000'
and likewise inconfig/environments/production.rb
1SITE_URL='myapplication.com'
Modify myapplication.com to reflect the url of your application. Make the production change toconfig/environments/test.rb.
- In both
config/environments/development.rb
andconfig/environments/development.rb
add aADMINEMAIL
variable representing the email address from whence you want the activation notices to be sent. Make the production change toconfig/environments/test.rb.
- Now we need to update the
app/models/user_mailer.rb
to pick up theSITE_URL
change. Any place there is a reference toYOURSITE
replace it with#{SITE_URL}
. - Next create
config/initializers/mail.rb
and place the following code in it:
123456789ActionMailer::Base.delivery_method = :smtpActionMailer::Base.smtp_settings = {:address => "mail.example-domain.com",:port => 25,:domain => "www.example-domain.com",:authentication => :login,:user_name => "user@example-domain.com",:password => "secret"}
You’ll need to change the settings to reflect your smtp settings. (The last three may not be needed—if that is the case, just remove them) - Don’t forget to remove
public/index.html
.
- As of 12 Aug, 2008, there’s an issue with rails and restful_authentication. To resolve this, according to Luca Guidi you need to make sure that the following lines are in
That’s a decent stopping point. In part II, we’ll look at adding OpenID and password retrieval. Part III will see us adding feeds. Part IV will add twitter.
Here’s the code so far: o_rly_parti.tar.gz
EDIT: Added changes needed to config/environments/test.rb to pass tests.