Upload
yohei-yasukawa
View
108
Download
1
Embed Size (px)
Citation preview
13
#Rails
http://railstutorial.jp/
Rails
by YassLab
Slideshare
http://www.slideshare.net/yasulab/presentations
Cloud9
1. 2. URL 3.
https://ide.c9.io/yasulab/rails-tutorial
https://rails-tutorial-yasulab.c9users.io/
URL “Collaborate” → “Group Chat”
! :)
Ready?
!
13
#Rails
http://railstutorial.jp/
Rails
by YassLab
DB
📨
✅ URL
❌ (NG )
⭕ (OK )
📝 email !
DB
📨
✅ URL
❌ (NG )
⭕(OK )
edit form
: assigns
@user
users_signup_test.rb
users_controller.rb
✅ 11 📨 🔒
•
✅ 12 📨 🔓
•
13 📮 🐤
•
14 👤 👤
•
1. Micropost (cf. 2, 4, 6 ) User Micropost − User has_many Microposts − Micropost belongs_to User
2. Micropost (cf. 7, 8, 9 )
3. Micropost (cf. 10 )
4. Micropost
13
Micropost
http://railstutorial.jp/
Rails
by YassLab
content Text :
- DB .
- ( ) .
Micropost
Micropost
Micropost
• Micropost $ rails generate model Micropost content:text user:references
Micropost
👆user_id:integer
👇
• Micropost $ rails generate model Micropost content:text user:references
Micropost
👇
•
• (Association)
Micropost
Micropost.find_by(user_id: user.id) user.microposts
Micropost.new(user_id: user.id) user.microposts.build
Micropost.create(user_id: user.id) user.microposts.create
Micropost.find_by(user_id: user.id, …) user.microposts.find_by(…)
: user.microposts.build(content: ‘1st post!’)
• Micropost default_scope -> { order(created_at: :desc) }👆 Micropost.first
• -> { … } Ruby Proc : p = -> { print ‘foo’ } ; p.call => ‘foo’
• User Micropost has_many :microposts, dependent: :destroy👆 User
Micropost
13
http://railstutorial.jp/
Rails
by YassLab
Micropost
🤔
📝
• 🚃 💨 Microposts
• 🔧 ( ) Partial
• 🐤 Users show
• 🌱 seeds
• 🎨 CSS
• ✅
• 🔍
Micropost
13
http://railstutorial.jp/
Rails
by YassLab
• / URL
• Microposts
• logged_in_user
• Microposts
Micropost (TDD )
🔧 Home
🔧 error_messages object
✅ Home /
Micropost
👈 shared/user_info
👈 shared/micropost_form
🔧
👤 where
👥
( )
🔧 _micropost
🔧 [delete]
🔧 [delete] DELETE destroy
13
http://railstutorial.jp/
Rails
by YassLab
Micropost
[Upload image]
Micropost • CarrierWave
$ rails generate uploader Picture $ rails generate migration \ add_picture_to_microposts picture:string
• MiniMagick $ sudo apt-get update $ sudo apt-get install imagemagick --fix-missing
• Fog ( ) Amazon S3 Bucket
1. Micropost (cf. 2, 4, 6 ) User Micropost − User has_many Microposts − Micropost belongs_to User
2. Micropost (cf. 7, 8, 9 )
3. Micropost (cf. 10 )
4. Micropost
Rails http://railsguides.jp/testing.html
Rails http://railsguides.jp/configuring.html
Rails http://railsguides.jp/engines.html
( ) !
13
#Rails
http://railstutorial.jp/
Rails
by YassLab