February 2008
7 posts
extending action_mailer
Recently a client wanted to use a web-based email system called JangoMail. JangoMail allows you to send emails, create distribution lists called groups, handle situations like bounces, etc. It also provides some reporting features for all your email statistics. JangoMail has an API that supports SOAP and also simple HTTP POST/GET requests. I decided to go with the POST version. Now I...
Feb 28th
less asking, more telling
Getting sick of writing the following? def create @user = User.new params[:user] if @user.save redirect_to @user else render :action => :new end end def update @user = User.find params[:id] if @user.update_attributes params[:user] redirect_to @user else render :action => :edit end end All this asking doesnt feel very...
Feb 25th
what, is it good for? absolutely nothing
Ever write this? before_filter :csv?, :only => :index def index respond_to do |format| format.html { @users = User.all } format.csv { @users = User.to_csv } end end def csv? if request.format == :csv && ! logged_in? log_in end end This would be a lot nicer if we could get rid of that #== in #csv? def csv? if request.format.csv? && ! logged_in? ...
Feb 22nd
4 tags
mean what you say
In a genuine effort to act more grown up, I’m putting down style and picking up markup. Getting back to roots not only feels good; it also makes for a handful of decent realizations. Websites should distribute content with consistent meaning to many devices on many platforms. Use of proper markup can make this a rich and meaningful experience. It’s easy to maintain this coding standard....
Feb 20th
4 tags
More Upcoming Events
I was very excited to have my talk selected for RailsConf. I’ll be presenting Advanced Active Record Techniques: Best Practice Refactoring – I hope to see you there. Tammer will be presenting BDD With Shoulda at ScotlandOnRails on April 4th-5th. And as we previously mentioned, he’ll also be presenting on Shoulda at the MountainWest RubyConf on March 28th and 29th. ...
Feb 18th
6 tags
When, a Rails plugin
Ever write this? before_filter :authorize protected def authorize unless logged_in? session[:return_to] = request.request_uri redirect_to login_url and return false end end You want your before_filter to authorize the current_user unless they are logged in. So why not say it like you mean it? before_filter :authorize, :unless => logged_in? protected def authorize ...
Feb 15th
4 tags
Riddle me this
Does anyone have a valid use case for ActiveRecord::Base#toggle! – inquiring minds want to know! The implementation from the rails codebase… def toggle!(attribute) toggle(attribute).update_attribute(attribute, self[attribute]) end So you send an ActiveRecord instance an attribute whose state you want to flip around, it flips it around, then it saves the instance with...
Feb 12th