Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ruby on Rails (the cool parts)
Search
Baylor Rae'
January 08, 2013
Programming
2
120
Ruby on Rails (the cool parts)
This is a presentation I gave that goes over "some" of the cool parts of Ruby on Rails.
Baylor Rae'
January 08, 2013
Tweet
Share
Other Decks in Programming
See All in Programming
Ruby×iOSアプリ開発 ~共に歩んだエコシステムの物語~
temoki
0
180
AIレビュアーをスケールさせるには / Scaling AI Reviewers
technuma
2
240
テストカバレッジ100%を10年続けて得られた学びと品質
mottyzzz
2
440
[FEConf 2025] 모노레포 절망편, 14개 레포로 부활하기까지 걸린 1년
mmmaxkim
0
1.4k
Flutter with Dart MCP: All You Need - 박제창 2025 I/O Extended Busan
itsmedreamwalker
0
110
Microsoft Orleans, Daprのアクターモデルを使い効率的に開発、デプロイを行うためのSekibanの試行錯誤 / Sekiban: Exploring Efficient Development and Deployment with Microsoft Orleans and Dapr Actor Models
tomohisa
0
230
Kiroで始めるAI-DLC
kaonash
2
520
さようなら Date。 ようこそTemporal! 3年間先行利用して得られた知見の共有
8beeeaaat
1
410
AIエージェント開発、DevOps and LLMOps
ymd65536
1
380
開発チーム・開発組織の設計改善スキルの向上
masuda220
PRO
18
9.7k
プロポーザル駆動学習 / Proposal-Driven Learning
mackey0225
2
360
実用的なGOCACHEPROG実装をするために / golang.tokyo #40
mazrean
1
140
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
462
33k
The Language of Interfaces
destraynor
160
25k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.6k
Designing for humans not robots
tammielis
253
25k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
61k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
139
34k
Become a Pro
speakerdeck
PRO
29
5.5k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
33
2.4k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
Scaling GitHub
holman
463
140k
Agile that works and the tools we love
rasmusluckow
330
21k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Transcript
3VCZPO3BJMT the cool parts ( )
8IBU`T$PPM "CPVU3BJMT %BUBCBTF.BOBHFNFOU 5IF"TTFU1JQFMJOF #VJMEJOH8FC'PSNT
%BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations %POFXJUI3BJMT.JHSBUJPOT w"MMDIBOHFTBSFDSFBUFEJOB3VCZpMF w%BUBCBTF"HOPTUJD w4ZODISPOJ[F&OWJSPONFOUT
%BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations $ rails g model Product title:string description:text price:decimal
db/migrate/2013010801384833_create_products.rb
%BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations $ rails g model Product title:string description:text price:decimal
db/migrate/2013010801384833_create_products.rb
%BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations class CreateProducts < ActiveRecord::Migration def up create_table :products
do |t| t.string :title t.text :description t.decimal :price t.timestamps end end def down drop_table :products end end
%BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations class CreateProducts < ActiveRecord::Migration def change create_table :products
do |t| t.string :title t.text :description t.decimal :price t.timestamps end end end
%BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations 1. add_column 2. add_index 3. change_column 4. change_table
5. create_table 6. drop_table 7. remove_column 8. remove_index 9. rename_column
%BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations 1. add_column :table_name, :column_name, :type 2. add_index, :table_name,
:column_name 3. change_column :table_name, :column_name, :type 4. change_table :table_name, options = {} 5. create_table :table_name, options = {} 6. drop_table :table_name 7. remove_column :table_name, *columns 8. remove_index :table_name, *columns 9. rename_column :table_name, :old_name, :new_name
%BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations $ rails g migration add_category_id_to_products category_id:integer db/migrate/2013010801448284_add_category_id_to_products.rb
%BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations class AddCategoryIdToProducts < ActiveRecord::Migration def change add_column :products,
:category_id, :integer end end
%BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations $ rake db:migrate
%BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations $ rake db:migrate == CreateProducts: migrating ================================================= --
create_table(:products) -> 0.0055s == CreateProducts: migrated (0.0056s) ======================================== == AddCategoryIdToProducts: migrating ======================================== -- add_column(:products, :category_id, :integer) -> 0.0015s == AddCategoryIdToProducts: migrated (0.0016s) ===============================
%BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations db/schema.rb ActiveRecord::Schema.define(:version => 2013010801448284) do create_table "products", :force
=> true do |t| t.string "title" t.text "description" t.decimal "price" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.integer "category_id" end end
%BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations $ rake db:schema:load
%BUBCBTF.BOBHFNFOU http://bit.ly/rails-migrations %POFXJUI3BJMT.JHSBUJPOT w"MMDIBOHFTBSFDSFBUFEJOB3VCZpMF w%BUBCBTF"HOPTUJD w4ZODISPOJ[F&OWJSPONFOUT
w1VMMTpMFTGSPNNVMUJQMFMPDBUJPOTJOUPPOF w3FNPWFTBl+VOL%SBXFSzPG+BWBTDSJQUpMFT w$PNQJMFTBOE$PNQSFTTFTUIFpMFT w"EETBCFUUFSDBDIFJOHTZTUFN 5IF"TTFU1JQFMJOF http://bit.ly/asset-pipeline
5IF"TTFU1JQFMJOF javascripts !"" bootstrap-dropdown.js !"" bootstrap-modal.js !"" bootstrap-popover.js !"" bootstrap-typeahead.js
!"" content-tabs.js !"" lightbox.js !"" jquery-ui.js !"" jquery-ui.progress-bar.js !"" jquery.anything-slider.js !"" navigation-tabs.js #"" site.js http://bit.ly/asset-pipeline
5IF"TTFU1JQFMJOF OFVTSBNCMJOHTCMPHTQPUDPN http://bit.ly/asset-pipeline
5IF"TTFU1JQFMJOF javascripts !"" bootstrap-dropdown.js !"" bootstrap-modal.js !"" bootstrap-popover.js !"" bootstrap-typeahead.js
!"" content-tabs.js !"" lightbox.js !"" jquery-ui.js !"" jquery-ui.progress-bar.js !"" jquery.anything-slider.js !"" navigation-tabs.js #"" site.js http://bit.ly/asset-pipeline
. !"" app $ #"" assets $ !"" javascripts $
#"" stylesheets !"" lib $ #"" assets $ !"" javascripts $ #"" stylesheets #"" vendor #"" assets !"" javascripts #"" stylesheets 5IF"TTFU1JQFMJOF http://bit.ly/asset-pipeline
5IF"TTFU1JQFMJOF http://bit.ly/asset-pipeline app/assets/js lib/assets/js vendor/assets/js !"" content-tabs.js #"" navigation-tabs.js !""
bootstrap $ !"" dropdown.js $ !"" modal.js $ !"" popover.js $ #"" typeahead.js !"" bootstrap.js !"" lightbox.js !"" jquery-ui.js !"" jquery-ui.progress-bar.js #"" jquery.anything-slider.js #"" site.js
5IF"TTFU1JQFMJOF http://bit.ly/asset-pipeline app/assets/js lib/assets/js vendor/assets/js !"" content-tabs.js #"" navigation-tabs.js !""
bootstrap $ !"" dropdown.js $ !"" modal.js $ !"" popover.js $ #"" typeahead.js !"" bootstrap.js !"" lightbox.js !"" jquery-ui.js !"" jquery-ui.progress-bar.js #"" jquery.anything-slider.js #"" site.js
5IF"TTFU1JQFMJOF http://bit.ly/asset-pipeline //= require bootstrap/dropdown //= require bootstrap/modal //= require
bootstrap/popover //= require bootstrap/typeahead CPPUTUSBQKT
5IF"TTFU1JQFMJOF http://bit.ly/asset-pipeline . #"" app #"" assets !"" javascripts/ #""
stylesheets/ application.js application.css
. #"" app #"" assets !"" javascripts/ #"" stylesheets/ 5IF"TTFU1JQFMJOF
application.js application.css http://bit.ly/asset-pipeline
5IF"TTFU1JQFMJOF //= require jquery //= require jquery_ujs //= require bootstrap
//= require_tree . /* *= require jquery-ui/datepicker *= require_self *= require_tree . */ application.js application.css http://bit.ly/asset-pipeline
5IF"TTFU1JQFMJOF http://bit.ly/asset-pipeline <%= javascript_include_tag "application" %>
5IF"TTFU1JQFMJOF
5IF"TTFU1JQFMJOF $ rake assets:precompile http://bit.ly/asset-pipeline
5IF"TTFU1JQFMJOF $ rake assets:precompile . #"" app #"" assets !""
javascripts/application.js #"" stylesheets/application.css http://bit.ly/asset-pipeline
5IF"TTFU1JQFMJOF public #"" assets !"" application-1b13569e9620782f423d4cd3ce931750.css !"" application-1b13569e9620782f423d4cd3ce931750.css.gz !"" application-32ed6ebaba49211fc69e08f40c7b97c4.js
!"" application-32ed6ebaba49211fc69e08f40c7b97c4.js.gz !"" application.css !"" application.css.gz !"" application.js !"" application.js.gz !"" manifest.yml !"" rails-a3386665c05a2d82f711a4aaa72d247c.png #"" rails.png http://bit.ly/asset-pipeline
5IF"TTFU1JQFMJOF public #"" assets !"" application-1b13569e9620782f423d4cd3ce931750.css !"" application-1b13569e9620782f423d4cd3ce931750.css.gz !"" application-32ed6ebaba49211fc69e08f40c7b97c4.js
!"" application-32ed6ebaba49211fc69e08f40c7b97c4.js.gz !"" application.css !"" application.css.gz !"" application.js !"" application.js.gz !"" manifest.yml !"" rails-a3386665c05a2d82f711a4aaa72d247c.png #"" rails.png http://bit.ly/asset-pipeline
5IF"TTFU1JQFMJOF public #"" assets !"" application-1b13569e9620782f423d4cd3ce931750.css !"" application-1b13569e9620782f423d4cd3ce931750.css.gz !"" application-32ed6ebaba49211fc69e08f40c7b97c4.js
!"" application-32ed6ebaba49211fc69e08f40c7b97c4.js.gz !"" application.css !"" application.css.gz !"" application.js !"" application.js.gz !"" manifest.yml !"" rails-a3386665c05a2d82f711a4aaa72d247c.png #"" rails.png http://bit.ly/asset-pipeline
5IF"TTFU1JQFMJOF <%= javascript_include_tag "application" %> <script src="/assets/application-32ed6eb...c7b97c4.js"></script> http://bit.ly/asset-pipeline
5IF"TTFU1JQFMJOF http://bit.ly/asset-pipeline
5IF"TTFU1JQFMJOF $ rake assets:precompile http://bit.ly/asset-pipeline
w1VMMTpMFTGSPNNVMUJQMFMPDBUJPOTJOUPPOF w3FNPWFTBl+VOL%SBXFSzPG+BWBTDSJQUpMFT w$PNQJMFTBOE$PNQSFTTFTUIFpMFT w"EETBCFUUFSDBDIFJOHTZTUFN 5IF"TTFU1JQFMJOF http://bit.ly/asset-pipeline
w$POWFOUJPOPWFS$POpHVSBUJPO w*OUFHSBUFTOJDFMZXJUI"DUJWF3FDPSE w#VJMEDPNQMFYGPSNT #VJMEJOH8FC'PSNT http://bit.ly/rails-forms
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms Product.new({ :title => "Cheese Crackers", :price => 3.99
})
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms Product.new(:title => "Cheese Crackers", :price => 3.99)
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms <form action="/products" method="post"> <!-- title --> <label for="title">Title</label>
<input type="text" name="title" id="title" /> <!-- price --> <label for="price">Price</label> <input type="number" name="price" id="price" /> <!-- doo wop --> <input type="submit">Create Product</input> </form>
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms <%= form_for Product.new do |f| %> <!-- title
--> <%= f.label :title %> <%= f.text_field :title %> <!-- price --> <%= f.label :price %> <%= f.number_field :price %> <!-- doo wop --> <%= f.submit %> <% end %>
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms <!-- title --> <label for="product_title">Title</label> <input type="text" name="product[title]"
id="product_title" /> <!-- price --> <label for="product_price">Price</label> <input type="number" name="product[price]" id="product_price" />
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms <!-- title --> <label for="product_title">Title</label> <input type="text" name="product[title]"
id="product_title" /> <!-- price --> <label for="product_price">Price</label> <input type="number" name="product[price]" id="product_price" />
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms params[:product]
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms params[:product] # {:title=>"My Product", :price=>12.5}
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms params[:product][:title] # "My Product" params[:product] # {:title=>"My Product",
:price=>12.5}
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms Product.new(:title => "My Product", :price => 12.5)
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms # POST /products def create @product = Product.new(params[:product])
end
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms lTUSPOHQBSBNFUFSTz github.com/rails/strong_parameters
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms class ProductsController < ApplicationController # POST /products def
create @products = Product.new(product_params) end private def product_params params.require(:product).permit(:title, :price) end end
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms # product_variation.rb class ProductVariation belongs_to :product end
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms # product.rb class Product has_many :product_variations end
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms <%= form_for @product do |f| %> <ul> <%=
f.fields_for :product_variations do |builder| %> <li> <%= builder.label :title %> <%= builder.text_field :title %> <br /> <%= builder.label :price, "$" %> <%= builder.number_field :price %> </li> <% end %> </ul> <% end %>
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms
#VJMEJOH8FC'PSNT http://bit.ly/rails-forms # product.rb class Product has_many :product_variations accepts_nested_attributes_for :product_variations,
:reject_if => lambda { |a| a[:title].blank? } end
w$POWFOUJPOPWFS$POpHVSBUJPO w*OUFHSBUFTOJDFMZXJUI"DUJWF3FDPSE w#VJMEDPNQMFYGPSNT #VJMEJOH8FC'PSNT http://bit.ly/rails-forms