Slides from my OSCON 2010 talk "Upgrading to Rails 3". For more information including a livecoding session of upgrading a simple Rails app from 2.3 to 3, visit http://bit.ly/rails-upgrade-talk
29. class Notifier < ActionMailer::Base
default :from => "mikel@example.org"
def welcome_email(user)
@name = user.name
attachments['terms.pdf'] = File.read(
Rails.root.join('docs/terms.pdf')
)
mail(:to => user.email, :subject => "G’day Mate!")
end
end
Thursday, July 22, 2010
30. class UsersController < ApplicationController
respond_to :html
def create
@user = User.new(params[:user])
Notifier.welcome_email(@user).deliver if @user.save
respond_with @user
end
end
Thursday, July 22, 2010
39. # Rails 3
def index
@books = Book.where(:author => params[:author])
if params[:author]
@books = @books.order(:title) if params[:sort] ==
'title'
respond_with @books
end
Thursday, July 22, 2010
40. # Rails 2.3
class Book
named_scope :written_by {|a| {:conditions => {:author => a}}}
named_scope :after {|d| {:conditions => ["published_on > ?", d]}}
# Rails 3
class Book
class << self
def written_by(name)
where(:author => name)
end
def after(date)
where(["published_on > ?", date])
end
end
end
Thursday, July 22, 2010
45. #lib/your_plugin/engine.rb
require "your_plugin"
require "rails"
module YourPlugin
class Engine < Rails::Engine
engine_name :your_plugin
end
end
Thursday, July 22, 2010