6
#Rails
Rails
by YassLab
http://railstutorial.jp/
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”
6
#Rails
http://railstutorial.jp/
Rails
by YassLab
1. Web − Home/About/Help/Signup − Bootstrap − Partial
2. Asset Pipeline Sass
3. (Integration Test) $ rails generate integration_test site_layout
4. $ rails generate controller Users new
Model-View-Controller (MVC)
Router
Controller
View
Model
DatabaseReq.
HTML
3
5
6
4
🤔 ( ) 📝
=> … 💦
DB 📥
=> DB … 😭
Rails Active Record (AR) ….!?
=> DB 👌✨
=> Ruby DB 💎✨
Model-View-Controller (MVC)
Router
Controller
View
Model
DatabaseReq.
HTML
…!!
AR !
Y^Y^Y^Y^Y^Y^Y^Y^Y^Y
1. $ rails generate model User name:string email:string
2. ? ?
3. has_secure_passoword
6
6.1 User
http://railstutorial.jp/
Rails
by YassLab
• User rails generate model User name:string email:string
• db/migrate/[timestamp]_create_users.rb
• (bundle exec rake db:migrate)
• (bundle exec rake db:rollback)
• db/development.sqlite3
• rails console
User
6
6.2
http://railstutorial.jp/
Rails
by YassLab
• (validate) :
• name ? ( )
• email ? ( )
• email ?
• : / / /
• User
: Regular Expression
528
Y^Y^Y^Y^Y
Rubular: http://rubular.com/
email/\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
(Unique)
1.
sample_app
[email protected]
2. ?
DB
[email protected]
sample_app
3. ?
4. email 5. email
6.
(Unique)
1.
sample_app
[email protected]
2. ?
DB
[email protected]
sample_app
3. ?
4. email 6. email
5.
!
7. email
><
6
6.3
http://railstutorial.jp/
Rails
by YassLab
• password_digest
• password_digest
• Rails has_secure_password DB
( DB )
• authenticate
•
DB
bcrypt
foobarhogehoge
$10$2FIEggLq.BFq7J17N7a9C.mTBgKeJ9uWanLq…
$2a$10$Kc/EY79ieCTBVYFktWkUKOhhY0kItaYPAyMsT23rvAR…
password_digest
• Test→Commit→Merge→Push 💨
…
⚠ Heroku push !
🔧 DB
• Heroku migrate console 💻 ☁$ heroku run rails db:migrate $ heroku run console --sandbox
1. $ rails generate model User name:string email:string
2. ? ?
3. has_secure_passoword
Model-View-Controller (MVC)
Router
Controller
View
Model
DatabaseReq.
HTML
3
5
6
4
Active Record http://railsguides.jp/active_record_basics.html
Active Record http://railsguides.jp/active_record_migrations.html
Active Record http://railsguides.jp/active_record_validations.html
1. Micropost (cf. 2, 4, 6 ) User Micropost − User has_many Microposts − Micropost belongs_to User
2. Micropost (cf. 7~8 )
3. Micropost (cf. 9 )
4. Micropost
1. Relationship
• User
• Relationship followed/follower
• follow
2. Ajax follow/unfollow UI
3. follow feed
4. / /
• :)
• : http://railstutorial.jp/seminars
• :) ,
.
• , .
6
#Rails
Rails
by YassLab
http://railstutorial.jp/