67. Rails 3
# controller
@cars = Car.where(:color => 'black')
# view
<% cache do %>
<% @cars.each do |car| %>
<%= car.name %>
<% end %>
<% end %>
68. Rails 3
Não acessa o
banco de dados
# controller
@cars = Car.where(:color => 'black')
# view
<% cache do %>
<% @cars.each do |car| %>
<%= car.name %>
<% end %>
<% end %>
69. Rails 3
Não acessa o
banco de dados
# controller
@cars = Car.where(:color => 'black')
Acessa o
# view
banco de dados
<% cache do %>
<% @cars.each do |car| %>
<%= car.name %>
<% end %>
<% end %>
79. class Notifier < ActionMailer::Base
default :from => "system@example.com"
def signup_notification(recipient)
@account = recipient
attachments['image.jpg'] = File.read("image.jpg")
mail(:to => recipient.email) do |format|
format.html
format.text
end
end
end
80. #1
Class level defaults
class Notifier < ActionMailer::Base
default :from => "system@example.com"
def signup_notification(recipient)
@account = recipient
attachments['image.jpg'] = File.read("image.jpg")
mail(:to => recipient.email) do |format|
format.html
format.text
end
end
end
81. #2
Variáveis de instância
class Notifier < ActionMailer::Base
default :from => "system@example.com"
def signup_notification(recipient)
@account = recipient
attachments['image.jpg'] = File.read("image.jpg")
mail(:to => recipient.email) do |format|
format.html
format.text
end
end
end
82. #3
Anexos são como cookies
class Notifier < ActionMailer::Base
default :from => "system@example.com"
def signup_notification(recipient)
@account = recipient
attachments['image.jpg'] = File.read("image.jpg")
mail(:to => recipient.email) do |format|
format.html
format.text
end
end
end
83. #4
mail funciona como respond_to
class Notifier < ActionMailer::Base
default :from => "system@example.com"
def signup_notification(recipient)
@account = recipient
attachments['image.jpg'] = File.read("image.jpg")
mail(:to => recipient.email) do |format|
format.html
format.text
end
end
end
88. class ContactForm
include ActiveModel::Conversion
extend ActiveModel::Naming
extend ActiveModel::Translation
include ActiveModel::Validations
attr_accessor :name, :email, :message
def deliver
valid? && Notifier.contact(self).deliver
end
def persisted?
false
end
end