SlideShare a Scribd company logo
1 of 29
Download to read offline
教科書にのってないから知らな
さそうな、でも知っておいても
いいよねっていうRubyの話
10th Webサービス/Webデザイン
かるぼ
✔もくじ
1.このLTのちょっとした背景
2.ぎちゅつの紹介
3.解説
1.このLTの背景
ECサービスを
作りました∼🎉
✔ざっくり
・Railsで作ったよ(Sinatraの大人ver)
・クレカ決済できるよ
・ドルにも対応してるよ
いろいろ調べつつ
「これ、教科書にのってなくね?」

みたいなのを集めました。
2.ぎちゅつの紹介
✔ざっくり
・validationとnull:false

・トランザクション処理
・createとcreate!

・accept

・join

・map

・中間テーブルの名前

・namespace

・module

・freeze

・ECの決済

・res = params[:key].map(&:to_i)
・whereと配列

・三項演算子

・res = Array.map { |t| { key: value } }

・is_a?、kind_of?

・class Range

・N+1問題・・・・
10分かあ、、、
2つくらいかな😇
・createとcreate!
・whereと配列
・まあ、知っておくべき
・メンバーのオリジナル作品の時に、
けっこう、役立つ
3.ぎちゅつの解説
✔ざっくり
・createとcreate!→エラーで止めるか
・whereと配列→一致をぜんぶ取ってこれる
createとcreate!

→「例外」の想定
テーブル
id:nilにして、Create
→何食わぬ顔で、実行されている
id:nilにして、Create!
→エラーを吐いて、処理を止めている
✔使い分け
ユーザの入力ミスを想定するか
✔例
ユーザが入力ミスした時、
いちいちエラー画面を出すのは
↓
エラーメッセージを出した方がいい
(よってcreate)
✔例
入力ミスをぜったいしないだろう
↓
100%データの保存が成功する時だ
け、create!がよき
whereと配列
→一致を全部取ってこれる
find→条件に当てはまった、最初の要素を返す
where→条件に当てはまっている要素を、全て返す
Product.where(id: [2,3])
✔いつ使うか?(例)
決済処理のとき
View Controller
買い物かご 処理
idの情報
1.hidden_fieldで隠し配列を送る
2.数値として、変換し直す
product_ids = params[:product_ids].map(&:to_i)
3.検索
.basket.products.where(id: product_ids)
残りは、、、ぼちぼち追記していきます😇
『かわそん』ってググってみてください。
(RPG)
更新情報出していきます∼!
このアイコン

More Related Content

Featured

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
Kurio // The Social Media Age(ncy)
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software
 

Featured (20)

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
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

Web lt-carbo