Название: [Книга+Исходники] Build a SaaS App in Ruby on Rails 5 Complete Package
Создаем приложение SAAS-типа на RoR 5.
Электронная книга, почти 600 страниц на английском языке. Издание 2017 года, но до сих пор содержит полезную информацию для созданию различных сервисов.
Подробности в описании.
Можно сказать, чистый эксклюзив (в паблике нет), если бы не год издания и появление обновленной версии книги для 6ой версии RoR.
Содержание книги. Опасно! Много букв
Содержание
Contents
Introduction v
0.1 WhoMightFindThisBookUseful? .............. v
0.2 HowthisBookisStructured?.................. vi
0.3 Acknowledgments ....................... vi
1 Ruby on Rails and your First Application 1
1.1 Prerequisites........................... 1
1.2 RailsOverview ......................... 2
1.2.1 Rails .......................... 2
1.2.2 Gems ........... 1.3 A Sample App to Get You Started
............... 3 ............... 4 ............... 4
1.3.1 RailsGem ........
1.3.2 InstallingRailsandStartingaNewApp . . . . . . . . 5
1.3.3 DirectoryStructure................... 6
1.3.4 RailsServer....................... 7
1.3.5 RailsConventions ................... 10
1.4 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 11 iii
iv
2
CONTENTS
1.5 Exercises ............................ 11
Testing and You 13
2.1 WhyTest ............................ 13
2.2 TestingFrameworks....................... 14
2.3 TestingTypes .......................... 16
2.3.1 Model/UnitTests.................... 16
2.3.2 ControllerTests..................... 17
2.3.3 ViewTests ....................... 18
2.3.4 FeatureTests ...................... 19
2.4 OtherTestingTools....................... 20
2.5 CIandYou ........................... 21
2.6 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 22
2.7 Exercises ............................ 23
Starting your SaaS App 25
3.1 railsnew...forrealthistime ................ 25
3.1.1 InstallPG........................ 25
3.1.2 rails newwithpg .................. 26
3.1.3 DatabaseConfiguration................. 26
3.2 Gitgudenuf........................... 27 3.2.1 GitCommands ..................... 28 3.2.2 GitUsage........................ 29
3.3 Gemfileandpreferredgemstostart. . . . . . . . . . . . . . . 31
3.4 UsingBootstrapinRails .................... 36
3
CONTENTS
v
3.4.1 QuickoverviewofGrid ................ 36
3.4.2 FirstController,ViewsandTests . . . . . . . . . . . . 38
3.4.3 Applicationlayout ................... 41
3.4.4 NavigationTop..................... 45
3.4.5 NavigationSidebar................... 48
3.4.6 Footer.......................... 49
3.4.7 Turbolinks ....................... 50
3.4.8 Onemorething... ................... 51
3.5 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 51
3.6 Exercises ............................ 52
4 Users are Everything 53
4.1 UserModel ........................... 54 4.1.1 InstallingDevise .................... 57 4.1.2 Signin,outandup ................... 62
4.2 UserManagement........................ 88
4.2.1 UserInvites....................... 89
4.2.2 UserRoles ....................... 89
4.2.3 FriendlyURLs ..................... 90
4.2.4 ManagingtheUsers .................. 92
4.2.5 TestingUserManagement ............... 105
4.2.6 CanCanCan....................... 119
4.3 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 132
4.4 Exercises ............................ 133
vi CONTENTS
5 Business Models and Logic 135
5.1 Scaffold,ifyoucan....................... 136 5.1.1 rails g scaffold ................. 138 5.1.2 Model.......................... 139 5.1.3 Controller........................ 140 5.1.4 Views.......................... 142
5.2 CreatingTheRemainingBusinessLogic . . . . . . . . . . . . 146 5.2.1 CurrentDate ...................... 146 5.2.2 TeamsusingHasManyThrough . . . . . . . . . . . . 160 5.2.3 Tasks with Single Table Inheritance . . . . . . . . . . 196
5.3 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 235
5.4 Exercises ............................ 235
6 Service Objects 237
6.1 WhatisaServiceObject?.................... 237 6.1.1 So...aserviceObject? ................. 238
6.2 Buildingandusingaserviceobjectinthisapp . . . . . . . . . 243
6.3 MoreusesforServiceObjects ................. 249
6.4 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 256
6.5 Exercise............................. 256
7 Background Jobs, ActiveJob and Sidekiq 257
7.1 WhatisaBackgroundJobandwhyuseone?. . . . . . . . . . 257
7.2 RightToolsforthe[background]job . . . . . . . . . . . . . . 258
7.2.1 ActiveJob........................ 259
CONTENTS vii
7.2.2 Sidekiq ......................... 263 7.2.3 Sneakers ........................ 263 7.2.4 SuckerPunch ...................... 264 7.2.5 OtherNotableMentions ................ 264
7.3 UsingSideKiqwithActiveJob ................. 264
7.4 OtherActiveJobtipsandtricks................. 265
7.5 ScheduledJobs ......................... 267
7.6 Procfiles............................. 278
7.7 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 280
7.8 Exercises ............................ 280
8 Mailers and You 281
8.1 WhatisaMailer?........................ 281
8.2 UsingaMailerinyourapplication ............... 283
8.2.1 AddingaWelcomeEmail ............... 283 8.2.2 EmailRecap ...................... 294 8.2.3 MailinProduction ................... 302
8.3 Receivingmailorreplies .................... 304
8.4 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 317
8.5 Exercises ............................ 318
9 What is ActionCable? 319 9.1 UsingActionCableinyourapplication . . . . . . . . . . . . . 321 9.1.1 UpdatingexistingStandups .............. 324
9.1.2 Adding a Standup to view on the User’s Standups page 335
viii
9.2 9.3 9.4 9.5
CONTENTS
9.1.3 Adding a Standup to view on the Teams’ Show page andStandupspage ................... 340
NavigationWebNotificationDropdown . . . . . . . . . . . . 344 TestingActionCable ...................... 351 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 361 Exercises ............................ 361
10 Stripe Payments and Subscriptions 363 10.1Stripe .............................. 363 10.2StripeGem ........................... 364 10.3Plans............................... 367 10.4NewAccount;NewSubscription................ 372 10.5BillingCenter.......................... 386
10.5.1 CancelaPlan...................... 392 10.5.2 UpdatetoFreePlan................... 396 10.5.3 UpdatetoPaidPlan................... 401 10.5.4 UpdatetoPaidPlanandAddaCard . . . . . . . . . . 404 10.5.5 UpdatingtheCard ................... 409 10.5.6 Checking for an Active Subscription . . . . . . . . . . 413 10.5.7 CheckingLimits .................... 416
10.6Webhooks............................ 418 10.6.1 StripeEventgem .................... 420 10.7TestingStripe.......................... 436 10.7.1 StripeRubyMock ................... 436
CONTENTS ix
10.7.2 ModelSpecs ...................... 437 10.7.3 ControllerSpecs .................... 438 10.7.4 JobSpecs........................ 452 10.7.5 Mailerspecs ...................... 458 10.7.6 TestEventDelegationObjects . . . . . . . . . . . . . 466 10.7.7 FeatureSpecs...................... 469
10.8 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 474 10.9Exercises ............................ 475
11 Using Third-Party APIs in your Application 477 11.1GithubIntegration........................ 478 11.1.1 GithubGems ...................... 478 11.1.2 Implementing Account and Github API . . . . . . . . 479 11.1.3 GrantingAccesstoGithubviaOAuth . . . . . . . . . 480 11.1.4 FetchingDatathroughGithub . . . . . . . . . . . . . 490 11.1.5 Accessing and Reacting to Github Webhooks . . . . . 505 11.1.6 DisplayingEventData ................. 514 11.1.7 TestingtheGithubIntegration . . . . . . . . . . . . . 521
11.2 Analytics:Whataretheygoodfor?. . . . . . . . . . . . . . . 546 11.2.1 Choices......................... 546 11.2.2 ImplementingandSendingevents . . . . . . . . . . . 547
11.3 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 553
11.4Exercises ............................ 554
12 Speeding up Rails 555
x
CONTENTS
12.1WhatSlowsRailsDown?.................... 556 12.1.1 N+1Queries...................... 557 12.1.2 Querieswithoutindices................. 559 12.1.3 Pagination ....................... 560 12.1.4 Gzip........................... 566
12.2Caching............................. 567 12.2.1 HowtoImplementCaching .............. 569 12.3 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 574
13 Deployments 575 13.1Therearemanychoices..................... 575 13.2Prepareapplication ....................... 576 13.3DeploywithHeroku ...................... 577 13.4DeploywithElasticBeanStalk ................. 579 13.5GettingStarted ......................... 580 13.6Therestofthegoodstuff.................... 582 13.7 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 586
Introduction v
0.1 WhoMightFindThisBookUseful? .............. v
0.2 HowthisBookisStructured?.................. vi
0.3 Acknowledgments ....................... vi
1 Ruby on Rails and your First Application 1
1.1 Prerequisites........................... 1
1.2 RailsOverview ......................... 2
1.2.1 Rails .......................... 2
1.2.2 Gems ........... 1.3 A Sample App to Get You Started
............... 3 ............... 4 ............... 4
1.3.1 RailsGem ........
1.3.2 InstallingRailsandStartingaNewApp . . . . . . . . 5
1.3.3 DirectoryStructure................... 6
1.3.4 RailsServer....................... 7
1.3.5 RailsConventions ................... 10
1.4 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 11 iii
iv
2
CONTENTS
1.5 Exercises ............................ 11
Testing and You 13
2.1 WhyTest ............................ 13
2.2 TestingFrameworks....................... 14
2.3 TestingTypes .......................... 16
2.3.1 Model/UnitTests.................... 16
2.3.2 ControllerTests..................... 17
2.3.3 ViewTests ....................... 18
2.3.4 FeatureTests ...................... 19
2.4 OtherTestingTools....................... 20
2.5 CIandYou ........................... 21
2.6 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 22
2.7 Exercises ............................ 23
Starting your SaaS App 25
3.1 railsnew...forrealthistime ................ 25
3.1.1 InstallPG........................ 25
3.1.2 rails newwithpg .................. 26
3.1.3 DatabaseConfiguration................. 26
3.2 Gitgudenuf........................... 27 3.2.1 GitCommands ..................... 28 3.2.2 GitUsage........................ 29
3.3 Gemfileandpreferredgemstostart. . . . . . . . . . . . . . . 31
3.4 UsingBootstrapinRails .................... 36
3
CONTENTS
v
3.4.1 QuickoverviewofGrid ................ 36
3.4.2 FirstController,ViewsandTests . . . . . . . . . . . . 38
3.4.3 Applicationlayout ................... 41
3.4.4 NavigationTop..................... 45
3.4.5 NavigationSidebar................... 48
3.4.6 Footer.......................... 49
3.4.7 Turbolinks ....................... 50
3.4.8 Onemorething... ................... 51
3.5 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 51
3.6 Exercises ............................ 52
4 Users are Everything 53
4.1 UserModel ........................... 54 4.1.1 InstallingDevise .................... 57 4.1.2 Signin,outandup ................... 62
4.2 UserManagement........................ 88
4.2.1 UserInvites....................... 89
4.2.2 UserRoles ....................... 89
4.2.3 FriendlyURLs ..................... 90
4.2.4 ManagingtheUsers .................. 92
4.2.5 TestingUserManagement ............... 105
4.2.6 CanCanCan....................... 119
4.3 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 132
4.4 Exercises ............................ 133
vi CONTENTS
5 Business Models and Logic 135
5.1 Scaffold,ifyoucan....................... 136 5.1.1 rails g scaffold ................. 138 5.1.2 Model.......................... 139 5.1.3 Controller........................ 140 5.1.4 Views.......................... 142
5.2 CreatingTheRemainingBusinessLogic . . . . . . . . . . . . 146 5.2.1 CurrentDate ...................... 146 5.2.2 TeamsusingHasManyThrough . . . . . . . . . . . . 160 5.2.3 Tasks with Single Table Inheritance . . . . . . . . . . 196
5.3 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 235
5.4 Exercises ............................ 235
6 Service Objects 237
6.1 WhatisaServiceObject?.................... 237 6.1.1 So...aserviceObject? ................. 238
6.2 Buildingandusingaserviceobjectinthisapp . . . . . . . . . 243
6.3 MoreusesforServiceObjects ................. 249
6.4 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 256
6.5 Exercise............................. 256
7 Background Jobs, ActiveJob and Sidekiq 257
7.1 WhatisaBackgroundJobandwhyuseone?. . . . . . . . . . 257
7.2 RightToolsforthe[background]job . . . . . . . . . . . . . . 258
7.2.1 ActiveJob........................ 259
CONTENTS vii
7.2.2 Sidekiq ......................... 263 7.2.3 Sneakers ........................ 263 7.2.4 SuckerPunch ...................... 264 7.2.5 OtherNotableMentions ................ 264
7.3 UsingSideKiqwithActiveJob ................. 264
7.4 OtherActiveJobtipsandtricks................. 265
7.5 ScheduledJobs ......................... 267
7.6 Procfiles............................. 278
7.7 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 280
7.8 Exercises ............................ 280
8 Mailers and You 281
8.1 WhatisaMailer?........................ 281
8.2 UsingaMailerinyourapplication ............... 283
8.2.1 AddingaWelcomeEmail ............... 283 8.2.2 EmailRecap ...................... 294 8.2.3 MailinProduction ................... 302
8.3 Receivingmailorreplies .................... 304
8.4 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 317
8.5 Exercises ............................ 318
9 What is ActionCable? 319 9.1 UsingActionCableinyourapplication . . . . . . . . . . . . . 321 9.1.1 UpdatingexistingStandups .............. 324
9.1.2 Adding a Standup to view on the User’s Standups page 335
viii
9.2 9.3 9.4 9.5
CONTENTS
9.1.3 Adding a Standup to view on the Teams’ Show page andStandupspage ................... 340
NavigationWebNotificationDropdown . . . . . . . . . . . . 344 TestingActionCable ...................... 351 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 361 Exercises ............................ 361
10 Stripe Payments and Subscriptions 363 10.1Stripe .............................. 363 10.2StripeGem ........................... 364 10.3Plans............................... 367 10.4NewAccount;NewSubscription................ 372 10.5BillingCenter.......................... 386
10.5.1 CancelaPlan...................... 392 10.5.2 UpdatetoFreePlan................... 396 10.5.3 UpdatetoPaidPlan................... 401 10.5.4 UpdatetoPaidPlanandAddaCard . . . . . . . . . . 404 10.5.5 UpdatingtheCard ................... 409 10.5.6 Checking for an Active Subscription . . . . . . . . . . 413 10.5.7 CheckingLimits .................... 416
10.6Webhooks............................ 418 10.6.1 StripeEventgem .................... 420 10.7TestingStripe.......................... 436 10.7.1 StripeRubyMock ................... 436
CONTENTS ix
10.7.2 ModelSpecs ...................... 437 10.7.3 ControllerSpecs .................... 438 10.7.4 JobSpecs........................ 452 10.7.5 Mailerspecs ...................... 458 10.7.6 TestEventDelegationObjects . . . . . . . . . . . . . 466 10.7.7 FeatureSpecs...................... 469
10.8 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 474 10.9Exercises ............................ 475
11 Using Third-Party APIs in your Application 477 11.1GithubIntegration........................ 478 11.1.1 GithubGems ...................... 478 11.1.2 Implementing Account and Github API . . . . . . . . 479 11.1.3 GrantingAccesstoGithubviaOAuth . . . . . . . . . 480 11.1.4 FetchingDatathroughGithub . . . . . . . . . . . . . 490 11.1.5 Accessing and Reacting to Github Webhooks . . . . . 505 11.1.6 DisplayingEventData ................. 514 11.1.7 TestingtheGithubIntegration . . . . . . . . . . . . . 521
11.2 Analytics:Whataretheygoodfor?. . . . . . . . . . . . . . . 546 11.2.1 Choices......................... 546 11.2.2 ImplementingandSendingevents . . . . . . . . . . . 547
11.3 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 553
11.4Exercises ............................ 554
12 Speeding up Rails 555
x
CONTENTS
12.1WhatSlowsRailsDown?.................... 556 12.1.1 N+1Queries...................... 557 12.1.2 Querieswithoutindices................. 559 12.1.3 Pagination ....................... 560 12.1.4 Gzip........................... 566
12.2Caching............................. 567 12.2.1 HowtoImplementCaching .............. 569 12.3 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 574
13 Deployments 575 13.1Therearemanychoices..................... 575 13.2Prepareapplication ....................... 576 13.3DeploywithHeroku ...................... 577 13.4DeploywithElasticBeanStalk ................. 579 13.5GettingStarted ......................... 580 13.6Therestofthegoodstuff.................... 582 13.7 Whatdidyoulearninthischapter?. . . . . . . . . . . . . . . 586
Подойдет и для начинающих.
Anonymous poster hash: 13f7c...9fa
Anonymous poster hash: 13f7c...9fa
Продажник:
Скачать: