no-www-rails is a simple rails extension, that redirects www.yoursite to yoursite using middleware.
www.yoursite
yoursite
Add it to your Gemfile:
Gemfile
gem 'no-www-rails'
No configuration required.