SlideShare a Scribd company logo
1 of 19
10 cool things in Rails 2.3



                    Luke Francl
Boots Faster in Development


       Empty Rails app (real time)
        time script/server -d

         Rails 2.2     Rails 2.3
          1.461s       0.869s
Boots Faster in Development

              n-
            no !
         lly Empty Rails app (real time)
              fic
       ta nti time script/server -d
     To cie
        s
             Rails 2.2      Rails 2.3
              1.461s         0.869s
Support for Rails Engines




                    Photo: Wikipedia
Routing Improvements
Routing Improvements
RESTful routes use 50% less memory
because formatted_* routes are no longer
generated.
Before:
formatted_users_path('xml')
formatted_users_path(:format => 'xml')

Now:
users_path(:format => 'xml')
Routing Improvements
Routes no longer inherit :only and :except.
Before:
map.resources :users, :only => :show do |user|
  user.resources :hobbies, :except => :none
end

Now:
map.resources :users, :only => :show do |user|
  user.resources :hobbies
end
JSON Improvements
JSON Improvements
JSON keys are always quoted, per the spec.
Before:
{123 => 'abc'}.to_json
=> '{123: quot;abcquot;}'

Now:
{123 => 'abc'}.to_json
=> '{quot;123quot;: quot;abcquot;}'
JSON Improvements
Unicode escape sequences are unescaped.
Before:
ActiveSupport::JSON.decode
  (quot;{'hello': 'fau00e7ade'}quot;)
=> {quot;helloquot;=>quot;fau00e7adequot;}

Now:
ActiveSupport::JSON.decode
  (quot;{'hello': 'fau00e7ade'}quot;)
=> {quot;helloquot;=>quot;façadequot;}
Default Scopes
default_scope :order => 'name asc'

# will use default scope
User.all
# will use passed in order option.
User.all(:order => 'name desc')

puts User.all.map { |u| quot;#{u.id} - #{u.name}quot; }

3 - Alice
2 - Bob
1 - George
Nested Transactions
User.transaction do
  user = User.create(:name => 'Luke')

  User.transaction(:requires_new => true) do
    user.hobbies.create(:name => 'Knitting')
    raise ActiveRecord::Rollback(quot;Oh noes!!!quot;)
  end
end
Asset Host Objects
class SslAssetHost
  def call(source, request)
    if request.ssl?
      quot;#{request.protocol}#{request.host_with_port}quot;
    else
      quot;#{request.protocol}assets.example.comquot;
    end
  end
end
Override Timestamp Fields

   User.create(:name => quot;Alicequot;,
   		          :created_at => 3.weeks.ago,
   		          :updated_at => 2.weeks.ago)

   => #<User id: 3, name: quot;Alicequot;,
   created_at: quot;2009-03-08 00:06:58quot;,
   updated_at: quot;2009-03-15 00:06:58quot;>
Nested Attributes...
class User < ActiveRecord::Base
 has_many :hobbies, :dependent => :destroy

  accepts_nested_attributes_for :hobbies
end

user = User.create(:name => 'Stan',
                   :hobbies_attributes =>
                   [{:name => 'Waterskiing'},
                    {:name => 'Hiking'}])
...and Forms
<% form_for(@user) do |f| %>
    <%= f.label :name, quot;User name:quot; %>
    <%= f.text_field :name %>

    <h2>Hobbies</h2>

    <% f.fields_for(:hobbies) do |hf| %>
      <%= hf.label :name, quot;Hobby name:quot; %>
      <%= hf.text_field :name %>
    <% end %>

  <%= f.submit 'Create' %>
<% end %>
Rails Metal
class UsersApi
  def self.call(env)
    if env['PATH_INFO'] =~ /^/users.js/
      [200,
        {'Content-Type' => 'application/json'},
        User.all.to_json]
    else
      # Return 404 to let Rails handle the request
      [404, {'Content-Type' => 'text/html'},
        'not found']
    end
  end
end
Rails Metal m/
class UsersApi
  def self.call(env)
    if env['PATH_INFO'] =~ /^/users.js/
      [200,
        {'Content-Type' => 'application/json'},
        User.all.to_json]
    else
      # Return 404 to let Rails handle the request
      [404, {'Content-Type' => 'text/html'},
        'not found']
    end
  end
end
Thanks!
Blog post:
http://railspikes.com/2009/3/30/10-cool-things-in-rails-23

Slides:
http://slideshare.net/lukefrancl/10-cool-things-about-rails-23

Code:
http://bitbucket.org/look/rails23-10coolfeatures/

Rails 2.3 Release Notes:
http://guides.rubyonrails.org/2_3_release_notes.html

More Related Content

Recently uploaded

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

Featured

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

10 Cool Things About Rails 2.3

  • 1. 10 cool things in Rails 2.3 Luke Francl
  • 2. Boots Faster in Development Empty Rails app (real time) time script/server -d Rails 2.2 Rails 2.3 1.461s 0.869s
  • 3. Boots Faster in Development n- no ! lly Empty Rails app (real time) fic ta nti time script/server -d To cie s Rails 2.2 Rails 2.3 1.461s 0.869s
  • 4. Support for Rails Engines Photo: Wikipedia
  • 6. Routing Improvements RESTful routes use 50% less memory because formatted_* routes are no longer generated. Before: formatted_users_path('xml') formatted_users_path(:format => 'xml') Now: users_path(:format => 'xml')
  • 7. Routing Improvements Routes no longer inherit :only and :except. Before: map.resources :users, :only => :show do |user| user.resources :hobbies, :except => :none end Now: map.resources :users, :only => :show do |user| user.resources :hobbies end
  • 9. JSON Improvements JSON keys are always quoted, per the spec. Before: {123 => 'abc'}.to_json => '{123: quot;abcquot;}' Now: {123 => 'abc'}.to_json => '{quot;123quot;: quot;abcquot;}'
  • 10. JSON Improvements Unicode escape sequences are unescaped. Before: ActiveSupport::JSON.decode (quot;{'hello': 'fau00e7ade'}quot;) => {quot;helloquot;=>quot;fau00e7adequot;} Now: ActiveSupport::JSON.decode (quot;{'hello': 'fau00e7ade'}quot;) => {quot;helloquot;=>quot;façadequot;}
  • 11. Default Scopes default_scope :order => 'name asc' # will use default scope User.all # will use passed in order option. User.all(:order => 'name desc') puts User.all.map { |u| quot;#{u.id} - #{u.name}quot; } 3 - Alice 2 - Bob 1 - George
  • 12. Nested Transactions User.transaction do user = User.create(:name => 'Luke') User.transaction(:requires_new => true) do user.hobbies.create(:name => 'Knitting') raise ActiveRecord::Rollback(quot;Oh noes!!!quot;) end end
  • 13. Asset Host Objects class SslAssetHost def call(source, request) if request.ssl? quot;#{request.protocol}#{request.host_with_port}quot; else quot;#{request.protocol}assets.example.comquot; end end end
  • 14. Override Timestamp Fields User.create(:name => quot;Alicequot;, :created_at => 3.weeks.ago, :updated_at => 2.weeks.ago) => #<User id: 3, name: quot;Alicequot;, created_at: quot;2009-03-08 00:06:58quot;, updated_at: quot;2009-03-15 00:06:58quot;>
  • 15. Nested Attributes... class User < ActiveRecord::Base has_many :hobbies, :dependent => :destroy accepts_nested_attributes_for :hobbies end user = User.create(:name => 'Stan', :hobbies_attributes => [{:name => 'Waterskiing'}, {:name => 'Hiking'}])
  • 16. ...and Forms <% form_for(@user) do |f| %> <%= f.label :name, quot;User name:quot; %> <%= f.text_field :name %> <h2>Hobbies</h2> <% f.fields_for(:hobbies) do |hf| %> <%= hf.label :name, quot;Hobby name:quot; %> <%= hf.text_field :name %> <% end %> <%= f.submit 'Create' %> <% end %>
  • 17. Rails Metal class UsersApi def self.call(env) if env['PATH_INFO'] =~ /^/users.js/ [200, {'Content-Type' => 'application/json'}, User.all.to_json] else # Return 404 to let Rails handle the request [404, {'Content-Type' => 'text/html'}, 'not found'] end end end
  • 18. Rails Metal m/ class UsersApi def self.call(env) if env['PATH_INFO'] =~ /^/users.js/ [200, {'Content-Type' => 'application/json'}, User.all.to_json] else # Return 404 to let Rails handle the request [404, {'Content-Type' => 'text/html'}, 'not found'] end end end

Editor's Notes