首页资源分类应用技术射频与通信技术 > Ruby on Rails 教程

Ruby on Rails 教程

已有 445109个资源

下载专区

上传者其他资源

    文档信息举报收藏

    标    签:Ruby

    分    享:

    文档简介

    Ruby on Rails 教程 样章

    文档预览

    Í,˟ 3 ʏ Ruby on Rails ØĨ ƌƂ Rails  Web ¬` õī Michael Hartl ̴ ŀο ͣ rev 1.0.0, 2014-11-26T18:00:00+08:00 ĝ¯ őuŮʼn § őű 2ʼnŧʼnİ# đìo'ĢÈìWţ Į 1 ī $Ƥ¬‰¶üƑň................................................................................................................... 1 1.1. İ# 2 1.2. ЫĔ~ 5 1.3. Į ©ė 7 1.4. 3ė Git 9đêËN 20 1.5. Ƒň 29 1.6. –Ŀ 33 1.7. ļ 33 Į 2 ī ē@©ė .......................................................................................................................................... 35 2.1. ŜG©ė 35 2.2. ė¸ŵċ 38 2.3. ±Yŵċ 49 2.4. –Ŀ 58 2.5. ļ 59 Į 3 ī }êƦ³ĜƩƨ ............................................................................................................................... 63 3.1. I«čĥ©ė 63 3.2. Ʀ³Ʃƨ 65 3.3. ¬‰ąŨ 73 3.4. çĎR³A“ĜƩƨ 78 3.5. –Ŀ 87 3.6. ļ 88 3.7. ƱĺąŨ¿ë 90 Į 4 ī Rails ŌkĜ Ruby ........................................................................................................................... 97 4.1. •Š 97 4.2. ‹ĭoÞă 100 v 4.3. ?&ÙÇij{ 106 4.4. Ruby ij 115 4.5. –Ŀ 123 4.6. ļ 123 vi - ĝ¯ őuŮʼn Ruby Ș ϚP̒ʬ͑ˤȬͪ͏…͑͝͞Ș“͔̋ː=öƘ)”David Heinemeier Hansson ŗȘʶύ/Ϊ ʁƼđŽÔ Rails ɆȹȒζǕ/ RubyRails ŭ́ˎ` Ruby on Railsľ͔ Web ŽÔ׃BȨΪ%Ƙ κ*BȨΪ%ˣÃđΣÎʬ•űRuby on Rails TutorialΪȪ,͉́"@˽cʡ Rails Ϋ̼ Web Ž Ôʬ{І̕ đΪʝ6̘ʬʤ͑ˤȬ̋ːû Web ŷʡŽÔχđ΢ʗÔŞƴƑȧƐ̞"ĎʬŽÔ̕ǫe Ruby on Rails Ě͕Ľ+̭ͪΪϚʤͪ͏ȘƑύͅʬX{ιΣɝͪĽ+ƍƍRȠȤǽȷɗĊ"Ϊɂƈ ʶ¦ŀοLjRuby on Rails Tutorial̓ͣƳȃȒƴƑЌ„ ƴBȨ¦ΣĎX łRđȨȱʬȺ Ĩ¦͞ŪȦƴ¦ĎȒ̞͆¦Ȫ,ʬ 8ͯ̕ ̀ƕʬ˄ˇaH Michael Hartl Ruby on Rails Tutorialʬ`̕ ϤÍȃ Ruby is a delightful computer language explicitly designed to make programmers happy. This philosophy influenced David Heinemeier Hansson to pick Ruby when implementing the Rails web framework. Ruby on Rails, as it’s often called, makes building custom web applications faster and easier than ever before. In the past few years, the Ruby on Rails Tutorial has become the leading introduction to web development with Rails. In our interconnected world, computer programming and web application development are rapidly rising in importance, and I am excited to support Ruby on Rails in China. Although it is important to learn English, which is the international language of programming, it’s often helpful at first to learn in your native language. It is for this reason that I am grateful to Andor Chen for producing the Chinese-language edition of the Ruby on Rails Tutorial book. I’ve never been to China, but I definitely plan to visit some day. I hope I’ll have the chance to meet some of you when I do! Best wishes and good luck, Michael Hartl Author The Ruby on Rails Tutorial vii § ƴ'ªţ`ʬ€åCD BabyȘħƃȋЏΕʡ Ruby on Rails ȣȑʬM' ʈëÐȠ±ƭʸĒǞĉ/ PHPđ Google Ǯ˯ƴʬêĻ̞Ǯ¦ƒ4Ϊēϟ«ʬȃ˜Ƒĥ=χƆʄǨ̯ Michael Hartl ʬΪȪ ,ƺGƴƒͯ ͯŁRuby on Rails TutorialëƴÐŽĶcʡ Rails sŽÔ/ ƴͯΣƑĥ Rails ʴƒʬ,XȘΪȪʷɗ͔ƴ~Ϛ/,όʬ ›χƑ˞è“Rails 'ο”ƴGª͋ƒΪ “ο”Ƒ̢ʈXȘͯŁΪȪ,ÊƯ̢͋ʈȌɟȪ,*Șā Ȫ̢Ķ̣˼χcʡ“ɭͤІ³Ž Ô”Test-driven Developmentˣˎ TDDʞƙʬ Rails ,˧Ƒĥ̼ŇχǨ̯cʡ TDDXȘđΪȪ,— ʏ'ªBɥȤ=IJɘɴɌĒ@˽ΣΪʞƙ,ʬɼˁŷʡΩʡ¦/ GitBitbucket û Heroku`̕ʷȘ ͔a\Ј/ LjŽÔʷɗ̞ʡʬŷʡȘ>%Ư̖͋,ʡ¦ʬEʼŲȘ–˓ǜλ—ȱʬ ˷ƟØΰȘƑıʬɏƁƴ̪/ĨʬȒϞ1 ϠͯȪ,ŁƳ/,ƺȤʬɼˁŷʡ*s/φ˸+B ị̄řƓŵɵΫͅΑʹͯΪɂƼ̞BÖʯ ;ÖΪȪ,ð Derek Sivers (sivers.org) CD Baby Ķ= 1. Ϊàŭ͆ͯŁȂȪ,̪ʬȒϞƍƍɟĨϙƑĥ ix őű Ruby on Rails ǿːƑħːźƇ°4ƴGªŽʬ Ȫ,——RailsSpaceĊɘGªʬè̴= Aurelius Prochazka *ȤƑħ°·ƴͅƯʹ AureD?"ª Ȫ,s—/͹ʙ̖*́0/ΪȪ,ǷǘƴΩ ͅƯʹ Debra Williams CauleyİȘ RailsSpace ûΪȪ,ʬ̋ΜÞͅİΩūƴÎʚɊʝƴŗR̄̆"İ Ž, ƴͅƯʹƑĥ Ruby ЌƻđΣÎΪ8űDHǿƴʺ͠*́ƴóίDHȘ David Heinemeier HanssonYehuda KatzCarl LercheJeremy KemperXavier NoriaRyan BatesGeoffrey GrosenbachPeter CooperMatt AimonettiMark BatesGregg PollackWayne E. SeguinAmy HoyDave ChelimskyPat MaddoxTom Preston-WernerChris WanstrathChad FowlerJosh SusserObie FernandezIan McFarland Steven BristolPratik NaikSarah MeiSarah AllenWolfram ArnoldAlex ChaffeeGiles BowkettEvan DornLong NguyenJames LindenbaumAdam WigginsTikhon BernstamRon EvansWyatt Greene Miles ForrestPivotal Labs €åʬıƕ=HHeroku ċϡthoughtbot €åʬőQUGÑ GitHub ʬ\ö ţȣëΩȤƑĥƑĥͯ̕ĩĥ/Ȍɧ $đȪ,Ž`ΣːÓЃ/OĥϝЀΏ/ƴƑĥ ż͖ƴʢ̀ĒƯʹΪ8=ʬŬ´Gѵ¯͔ΪȪ,׃Ƞı xi 2ʼnŧʼnİ# Ȫ,̭ȃʏÍ`̕Ș Michael HartlLj Ruby on Rails Web ŽÔ@˽́=ʬ{̼̕' *Ș̢—ʏŰá SoftCover ʬ̘è Ķ=D'ªȡ˾Ž`ŲŽÔ/ RailsSpace ȪƑΣȒʬ Rails ǿː *ȡcʡ Ruby on Rails ŽÔΣ ê" Insoshi ʬ˂9̏̂ŰáΪŰáȡ˾Ƒɬ̼ʜđŨ˾Σɣ/Ċ"DŌ Ruby ˂½ ʬ͹ʙ4 2011 ű́ǡ0/ Ruby Hero ĮDɠ4ý_ĽϩŲ̰ƒ/±ŢʞţĽϩʬʑʞĽÅğĽY DΩȘ Y Combinator ̕Ϲʲʬɠʠ Ȫ,ˣ\ȃʏʢŀὀͣDȘ ê̓ͣʋı̕ ʳđĽ+cʡ RubyŨ˾̓ͣĥȪ Rails ʴƒʬ, ˧dIJcʡ RSpec ɭͤ Rails ːŵûRails ːŵφ̑'οˠ xiii đìo'ĢÈìWţ Ȫ,ȘRuby on Rails Tutorial: Learn Web Development with Rails (Third Edition) ,ʬˣ\ȃʏʢ`̕ Michael Hartl ǡȮŀὀͣûϕĀʏȮƇ Michael Hartl ûŀοƺȤ Ȫ,ÖʏȮɧiNJK]˹˻Ƶ=ƒGK]ƊƁšÔƵsĂcʡ ,Eʼě4 MIT Â͖û Beerware Â͖Ôũ The MIT License Copyright (c) 2014 Michael Hartl Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* * ---------------------------------------------------------------------------* "THE BEERWARE LICENSE" (Revision 43): * Michael Hartl wrote this code. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. * ---------------------------------------------------------------------------*/ xv Į 1 ī $Ƥ¬‰¶üƑň ɑΥϠͯRuby on Rails ǿː ιΣ Rails Ľ+ Web ŽÔȪ,ʬʲʬȘǿaIJ]ŽÔ Web ŷʡ̖ƴH ζǕʬţ†Șɬ̼ʬ Ruby on Rails Web ɆȹIJȷaŸǦ͎Ϊ ϾęȪ,Rìaͩ˺@˽ Web ŷʡŽÔ ʬȈȈ϶϶ºǖ RubyRailsHTML û CSSȁǟŶʏȪǧ§ɭͤGÑφ̑ʬěȪʺ͠ĽRΪ 8ʺ͠ΌĦ"a΅ƒ L Web ŽÔ̕ʬţ`Ƶ̕ΩàG͔aƳ" êLJȫ ̕IJȷaŨ˾/͍ Web ŽÔϠͯȪ,̞ƘκĽR Rails Ɇȹʬěʿºǖ MVC û RESTʠƳćΡˏΐʢGÑš~Ɓ Ruby˥ƜɂͯŁȪ,'ëGaƺǣǭʬʺ͠Ũ˾̞ĦϠ͓ͯ͜ȠЌ˴ͦЀʬď,ûÅŅƵ͇̕ʶ ͉ϿΪ8χȘȓʱʬ̋ːǿĽʠƛĐʬ φš1 Ȫ,ϊʡ ˋ̈èƁȈɧ͙ǡ Web ŽÔđĽ+ʬΣːƴHͅŽÔɼˁŷʡ ˟ ȣˣÃß hello_app1.3 ̩ ˟3°̞ĥ 8ß toy_app˟ 2 ˜˟Șʷɗʬɼˁːŵß sample_app˟ 3 ˜¦˟ 12 ˜BΪŷʡʬêĻàGʶ—,ŽÔʬŷʡϨł4Ⱥˋʒł˨ėʬ̏ ˚Σȣë ɼˁŷʡȤʁw˨WȺɬ̼ʬ˂R»ƔÅ̏˚ƑťΪ̏˚ ŽĶ*Șcʡ Rails ŽÔʬȪ,ʬύʁȘ@˽ιʡ͞ƺG˥aƬŽÔ>%ɂʬ Web ŷʡͯŁȪ,ëχ̞ż˘ƽŃ ʬěʿ =H˾ŭRϝƴͅ†ĢĥŒ̜țʺ͠Ƽ̞ϠͯȪ,Ľ+ Web ŽÔ1.1.1 ̩Ōɘs/ͩ˺šȵWeb ŽÔ Ș†ȤǛƶƟʬĽˌŌɥȤK]̜țʺ͠ʬ¡Ľ̕ȱͭǛƶȠħƴȣ¡"Ȫ,͝łʬϠͯŌͶȘŨ˾ †Ȥ ł̋ːû Web ŽÔ˾ЈʬŽÔ̕XëȱÔʜͯ̕ȤƑĥχŸŽĶǦ͎ŽÔƺGʜđaʶ¦ʬ Ȫ,˟ʏs—/Ƒĥµ¯ŘώϧZ/~Ϛ Rails ʬϚɎ ߥ 1.1Ơ/Ɲú Ȫ,˟ʏϊÕ/ƑĥǩȉϧZ~Ϛ Rails ʬϚɎ • cʡ5˝Ⱦ’ʬŽÔʛĝ1.2 ̩͈ς/ŀ̓ûψ̐ȇ˭̃ɰѦʬƑĥϝЀ • èʞ¤ʡ Rails Ў͒ǫeʬ˹IdIJÍʠʬ MiniTest ɭͤɆȹ • ¢Ǣ/ƑĥĤφf΄IRSpecCucumberCapybaraFactory Girl • cʡ ˋȠΘώ˴ȠɿɫʬɭͤȈƁ • Żë@˽Ƶ̕¢Ϫ/Κ"ģȭʬψ̐ζϹGuardSporkRubyTest • Ƅ»Ⱥ Rails ʏȪʒȤʬ°̞Ƞ±Ɔͱ Web ŽÔʬιʡ͞ ƴŪȦΪ8×»̞͔Ȫ,˟ʏ̰ƒɟª ʏȠĥʬͯ̕ Ϊ˟ ˜ƴHͅŀ̓ Ruby on Rails GÑϳͅʬƺȤΗI̖ῼȹ͝ŽÔʛĝ1.2 ̩ʈë ż˟  Rails ŷʡhello_appȪ,Ȑđ@˽PˉʬΗIŽÔ+ƫƺGđ ż˟ ŷʡ'ëƴHR˘É 1. Ȫ,ȣȇʏàGđȪ,̏˚̰ÕĒĔȘ http://railstutorial-china.orgIJȷaʶʬȘˈ˷ʏ ł͞ͅϝđ˷ʏ̰Õȣ ΧʬȠȇ 1 Őľ˶~ʏȪǧ§˭̃ Git 1.4 ̩aà̞ʴjđΪ ˜ƴHῼφ̑Ϊŷʡ1.5 ̩Lj ľǻ¦Ĥ̏ ˟ 2 ˜R ż˟3Ϲʲɼˁ Rails ŷʡʬ 8ěȪǵ`"/κźƴHRcʡ̡ƻȹȊɩ 1.2 ż Ϊŷʡê" toy_appĊ"ʠƳʬEʼƑ*ƑģȭƺG˟ 2 ˜Őϱ˫¯đɮ͊ćcʡ URI˾ŭˎ" URL2 ûΪŷʡ96 Ȫ,¬ʬ˜̩Őϱ˫¯ŽÔ ʷŃʬħėɼˁŷʡê" sample_appƺȤEʼχBϲŽĶ̋Ž đŽÔΪŷʡʬΣːƴHRʡ¦ɏǓLJȫ“ɭͤІ³ŽÔ”Test-driven Developmentˣˎ TDDʞ ƙGÑ“ϱƳɭͤ”integration test˟ 3 ˜ żϴƛϷ϶ʈëб 8³ƛŠň˟ 4 ˜Rˣͅ@˽  Rails cʡʬ Ruby ːŵͪ͏˟ 5 ˜¦˟ 10 ˜ŐηəŁĄΪŷʡʬZś̀ȴºǖ̏˚ʬũŚʡ ƹȁǟɏėŁȂʬɩ‹û͒͟˭̃ñȤͼƹɾɫûŊʼύ͝°̞ȣë˟ 11 ˜û˟ 12 ˜Őɳ±Ɣ Åû˂9°̞ȣ˼ŽÔ— àGɗŭΦ̼ʬɼˁ̏˚ ߥ 1.2ŏºñ——å²åİXåū Rails —ʜNĶŗôƂ/Oĥʲ|ʒ¥Ș Rails Ķ= David Heinemeier Hansson Ɖ§ʬ̴êʬ“15šϐ ŽÔ ÅŅːŵ”͉ϿΪ͉Ͽх̽ʠʏȪȘ˗ǥ Rails Ɔħ°̞ ˋƑıʬȈƁƴǨ̯aʶ Ϊ8͉ϿΣ2{ǫω Ϊ8͉Ͽʬɼˁ̞ǧ§đ 15 šϐGŠƒʯ4 ˋßs“̡ƻ ȹ”scaffoldʬ°̞ιΣ Rails úF generate scaffold ʠƳħώʬEʼ Ž`Ȫ,Ȓƴ*ƬΣcʡ̡ƻȹĊ"ľȠƘȠˣÃȠͬ=Σ̡ƻȹʠƳʬħώģȭʬE ʼR͔¡Ľ̕ČƩ̺ʈ̞ĽR̡ƻȹʬʡɧXŲȔʪ¦ŸÔʠ/>%2cʡ̡ƻȹaÞȘ ̡ȪʠƳćʬcʡ̕ȌɧǫÁaŌ Rails ʬ͒͠ Ȫ,Őϊʡ ˋéʬȈƁ̺ʈ˟ 2 ˜Rʡ̡ƻȹŽÔ őėʬʚ†ŷʡXȪ,ʬɃƕȘB˟ 3 ˜ΈŽÔʬɼˁŷʡđŽÔΪɼˁŷʡʬɞϣɛƴHÞR̋ŽŒώʬEʼȕ4ʞ͍XІȤ łʬǛƶƟιΣΪ Σːȣ˼aRŌ Rails ȤΚ"ɱ©ʬʞ͍̖̞ɿɫΦʡŽÔ•(K] ˨ėʬ Web ŷʡ 1.1. İ# Ruby on RailsƵ̕ˣˎ“Rails”Ș  Web ŽÔɆȹcʡ Ruby ̋ːͪ͏ŽÔ̢ 2004 ű—ʜ'ë Rails ŗ΢κƳ"³ƛ Web ŷʡŽÔϾę°̞ȣƆħȣÖɑΥʬɆȹ' cʡ Rails ʬ€åȤƑĥdIJ AirbnbBasecampDisneyGithubHuluKickstarterShopifyTwitter û Yellow PagesΩȤƑĥ Web ŽÔţ`ņϚB2 Rails ŷʡŽÔdIJ ENTPthoughtbotPivotal LabsHashrocket û HappyFunCorp Ϫɘ'ĤΩȤȌȁʖ˘ϼϝĚ͕=öûϹʲdžºĂ Rails "]IJɘƳ°÷ Є{Rails ŁŽɸě4 MIT Â͖ÔũàG}΁ΙcʡRails ʬƳ°Ƒħ ːźƒʯ4ľPϰ̖˰”ʬ͑͝Rails ʊͳ Ruby ͪ͏ʬàǁŞƟŽÔ/ įʡ4̋Ž Web ŷʡʬ“Ͼ ęʒłͪ͏”Domain-specific Languageˣˎ DSLƺG Web ̋ːƑĥŭ͆ʬK²dIJʠƳ HTML żȁǟɏėû URL ΐʢđ Rails χƑňȕŃʜȣ˼ƒ¦ʬŷʡEʼˣɪ̖àͯƟЌ Rails ΩRƘκΎΫ Web ŽÔϾęȣȇʬLJȫûɆȹ͑͝ȈƁdIJRails Șȣȑcʡ REST ȹȴЂɅ˹˻ Web ŷʡʬɆȹ' ΪȹȴͿ˔Ȫ,ƈ…DɆȹŽÔ—Ƴ°ʬȇLJȫëRails ʬ ż̕ David 2. URI Ș“̃ ΂ɸȾ͠˞”Uniform Resource IdentifierʬˣˎΚŒcʡʬ URL Ș“̃ ΂ɸłY˞”Uniform Resource LocatorʬˣˎđŃϥcʡURL ̦ûɮ͊ćĒĔȿʬŠň ɂ 2 - Į 1 ī $Ƥ¬‰¶üƑň Heinemeier Hansson хɃƕŽÔċϡRɢʕͷʬՅô˶ΫȱƵ͛ȣ‡ėʬdĺȘ Rails û Merb  ϹʲʬèŲBɘ Rails ̄dž/ Merb ʬɏĖ»͑͝˒łʬ APIƟ̞*ƒ¦/ǫÁ ȣë ʁRails Ȥ ɫ΍̖ĥy»ʬ˂½˂½ȤȁGʫ͑ʬŽɸϹʲ͹ʙ̕GÑR̕OĥʬŽÔ ̕ħR̖ΩŽÔ/ħώʬ gemEʼŶ  gem ͍ ʒłʬϝЀdIJšϷûďʎSȤƑ ĥŠňŋʬÅŅGÑ 8͓͜˹û IRC ϿοȤIJɘOĥʬ Rails ːŵö*cƒġʞːŵϖͫ׃ˣà / đ͵ɕǮ˯ϖͫɯƣ•(ơ̞Dž¦ ˦ʴƒʬÅŅȃ˜Ƶ͓͜˹ʬͦЀ 1.1.1. ƬġŦ ϠͯȪ,ϳͅ†ĢʒłʬϽĢʺ͠Ȫ,?@˽ RailsΩɰÑŸśʬ Ruby ͪ͏Rails Ў͒cʡʬɭͤ ɆȹMiniTestUnix úF̼HTMLCSSŒώʬ JavaScriptGÑ ʁ SQLƴHͅǣǭʬʺ͠Ƒ ĥƺGƴ ̦ż͖ϠͯȪ,'ª{†Ģ 8 HTML û̋ːʺͭ͠ȘΪ%ͭX*Ȥʴƈȁώʬ¡Ľ̕c ʡȪ,BϲŽĶĽ+ Web ŽÔƺGÉgaʬ˾ЈȤϨƴΩȘż͖aͯ ͤͤIJȷaǒȹ[/Ϭ ȒàG̓ĉΪόcʡ϶—ʬȺ΂ɸBīĽΈĥYͯ̕õ͡ƴDHż͖Ύʹǿːsξ˟ ξɠ˛Ľ¦ʬʺ͠ȤϨXŒs˟3ξŗˣÃĥ/ Ľ+ Rails Ȓ˾ŭȤ=ϝͅͅ{Ľ RubyΪϝЀʬˡɇՐ4a=ʬĽ+ȈƁGÑ̋ː˾ЈIJȷ aŪȦΚ"˭̃ĒƌŸĽ+Ƶ̕aGªBȨ̋ːΣτ%{Ľ Ruby Ƶ͛ȠèεĽ+ RubyƴǨ̯Ϡͯ Chris Pine ŽʬLearn to Programû Peter Cooper ŽʬRuby ~ϚƑĥ Rails ¡Ľ̕ƑƬ˘ÉŽĶŽÔ Web ŷʡ̖Șđɘ'ªͯŁ Ȫ@˽ Ruby ʬ,IJȷaȘΪ˨=ƴǨ̯ađ Try Ruby Ľ+ 8ˣ ʻʬ96ƁǿːGgđϠͯȪ,'ªŌ Ruby Ȥħɍʬ/͍IJȷaΩȘ͋ƒȪ,ĩϯƵ͛àG{ʶ Daniel Kehoe ŽʬLearn Ruby on RailsƵ̕Ľ+ One Month Rails Ͱː——ľHȠεèɥȤK]̜țʺ͠ ʬ¡Ľ̕ ˥aBÿόŽĶͯŁȪ,ëχŷͨàGĽ+ Rails Ќ˴ʺ͠/GȘƴǨ̯ʬ 8Ľ+΂ɸ • Code School Ƒıʬ96Ɓ̋ːͰː • Tealeaf Academy Ƒıʬđ˷ Rails ŽÔ͕˸̲ºñЌ˴ʺ͠ • Thinkful đ˷ͰːûȪ,ʬϯźŦĥ • Ryan Bates #ǘʬ RailsCasts Pˉʬ Rails ͉Ͽħĥȁ}΁ • RailsApps ƑĥϏŌʒłͦЀʬ Rails ϹʲûǿːͭȔͩ˺ • Rails ǙÄ ǚͦЀ̋Žʬ Rails Ï̔˾ŭȠȇ3 1.1.2. ÉđŐ Ȫ,cʡʬǤʏȈƁƑĥχʡŒs͍ϋȪ̩ƴͭͅ τ8Ʈ&ȘƑɴȜʬǤʏ ,ƑĥEʼɴÃʡ¦/úF̼úF"/̼ȃˣgƺȤúFχcʡ Unix ЂɅúF̼ǫˁ˞ ̒y˞ ädIJ $ echo "hello, world!" hello, world! 3. ͣ̕ɩ Rails ǙÄŨʢȪ,ͣ̓ͣ̕Ƴȃʣĺ,;-ĒĔ https://selfstore.io/products/13 1.1. İ# - 3 đ 1.2 ̩ƴRǫ¦˥acʡÿˋǵ`˭̃Ŗ…Ș Windowsƴχż͖cʡ5˝ŽÔʛĝ1.2.1 ̩ΪˋʛĝχŠ̐/ UnixLinuxúF̼úF̼¿šȤʡĊ" Rails ǫe/ƑĥàGđúF̼Φ ̼ʬúFdIJđ 1.3.2 ̩ƴHRcʡ rails server úFó³ȪĒʬ Web ŽÔȥ²ć $ rails server ûúF̼ǫˁ˞ ɂȪ,*Rcʡ Unix ƫʡʬʲƉšϮ˞Éȅ˷ /dIJɼˁŷʡʬψ̐ȃI production.rbľʬΐƏȘ config/environments/production.rb ΪȃIΐƏʴŌ4ŷʡʬɄʲƉđéʬ˭̃ɄʲƉRȤŦ¥đ5˝ IDE ɄʲƉv϶Ϊ ɂ /home/ubuntu/workspace/sample_app/ ƺGproduction.rb ʬŁȂΐƏȘ /home/ubuntu/workspace/sample_app/config/environments/production.rb "/̼ȃˣɪƴ ̦χRʵʦŷʡʬΐƏŽƳ config/environments/production.rb Ȫ,˾ŭϳͅșˁ 8ȱ̢…Dːŵshell úFʏȪǧ§˭̃Ruby ːŵˠʬΝ—Ċ"˭̃'Ϟļ đ˺ƔʬŦžaʶ¦ʬΝ—̀ȷà̞û,șˁʬŁ ̤XȘȌϳǏƕ̖Ȥ8úFđȺ8ǵ `˭̃à̞RŎ̤ϖͫȪ,R ͭȔΪ8ϖͫʬ͍ȈɧaàGđ͵ɕǮ˯ϖͫɯƣ̢ŧŕ ͍ͤ——Ϊ*Ș"ʜŃʬΗIŽÔs’ĢIJȷađϠͯȪ,ʬΣːν¦/ϝЀƴż͖aʶ Ȫ ,̏˚Ŭ´½—ʬ΂ɸ đΪǿːƴHͅɭͤ Rails ŷʡƺGȣıʺοȺɛEʼ̞͔ɭͤ˹IĪͻcʡ˲̨̿ˁΩȘιΣ cʡ̨̉̿ˁ"/ȈgŎ̤ɭͤĪͻʬEʼcʡ“RED”Ⱦ̞͔͘ɭͤιΣʬEʼcʡ“GREEN”Ⱦ ͘ ɞ ˜χȤ 8˸+aàG̢ŧłͅͅsXǨ̯s"/½šɗȃû˸+˸+ʬ͍ˡRûë̆ ʬŠňɲđ ΈIJȷë϶ϳͅcʡȺ˸+ʬEʼƴRđɗȃǙ—ȱŲ́—͍ˡȈɧ ȣë"/ȈgȪ,cʡˋǤʏȈƁ͔EʼɴÃȠȕʞ͍˟ ˋȤ8Eʼɴúñ ¦ĥЌ <ʬEʼ̼IJƺˁ class User < ActiveRecord::Base validates :name, presence: true validates :email, presence: true end Ќ<ʬEʼ̼ ̦ʡ4Ⱦ—ΪɛEʼɴÃȣύͅʬȇEʼtœ*ʡȱ̿ˁƈªEʼɴÃûª Eʼɴ ÃʬŦž˟3ˋ"/̼ȃˣɪ,ƑĥEʼɴÃχȤ˙ǤʬʁäIJƺˁ class User < ActiveRecord::Base . . . has_secure_password end Ϊ8ʁä̿ˁʵʦʬEʼͅʳǦģ§ 4 - Į 1 ī $Ƥ¬‰¶üƑň 1.2. ЫĔ~ ŗˤŌ˾Јŋʬ Rails ŽÔ̕ȱͭŀ̓ RubyRailsGÑʴƒʬƺȤΗI*ͅ•˾ɨljΪ8ϝЀȘ ʢʛĝʬĥɂƟŎ̤ʬéʬǵ`˭̃ʏȪäȃȪ̋Μćʬrı̐͝û“ϱƳŽÔʛĝ”Integrated Development Environmentˣˎ IDEˠχRŎ̤ʛĝȤƺéIJȷaŨ˾đȪĒʣ̠ψ̐ı/ŽÔ ʛĝàḠ̆cʡaʬʛĝXŌ4¡Ľ̕ƴȠЏ¶cʡ5˝ϱƳŽÔʛĝȊɩ 1.1ͭΣΪɂà Gς}ŀ̓ûψ̐—ʜϝЀ5˝ IDE Φ̼đȚιʬ Web ɮ͊ćĊɘđéʬŰá̿ʜ ̤ΪŌ Rails ŽÔ ʳƑČϯʬǵ`˭̃dIJ WindowsȱͭŖ…ȤʡIJȷaƝǛƶAƬđȪĒŽÔʛĝ Ľ+,ʬǿːƴż͖aǚʉ InstallRails.com ʬͭȔǰżʛĝ4 1.2.1. ¬`Ĕ~ éʬ=Ȥéʬąıɞ Rails ːŵöχȤ į̢ŧʬŽÔʛĝ"/ς}ϝЀģȭ»Ȫ,cʡ  Ⱦ’ʬ5˝ŽÔʛĝCloud9̖"/˟ʏƴΩû Cloud9 è`"Ȫ,ώΓƾλ/ ŽÔʛĝ ΪŽÔʛĝϽ{ŀ̓ı/ Rails ŽÔƺϳʬħĥȁΗIºǖ RubyRubyGems û Git…ŃāȤ Rails ͅÃʖŀ̖̓Ϊ%sȘȤʲʬʬͩƧÏ͆ 1.2.2 ̩Ϊ5˝ IDE Ωºñ Web ŷʡŽÔƺϳʬ ěȪ˹I ȃȪ̋ΜćȃI˭̃ɮ͊ćGÑúF̼˼˝IJď 1.15˝ IDE ʬȃȪ̋Μć°̞Ƒ ĥ… ϹȘ“đȃIȼDž”ʬŚǮ˯°̞5 ƴ͋ƒΪ°̞Ōħė Rails ϹʲȱͭȘƖĢʬ v 1.1Ĭ IDE ĜĚƨ¡š Ϊ5˝ŽÔʛĝʬcʡəЊIJ 4. ŗˤΪɂƴΩȘͅǫω Windows ʡƹInstallRails Ǩ̯cʡʬ Rails ŀ̓ºƍƍʏȪΣȏà̞ΎȪ,ʬǿː‰ň 5. dIJͅƬDž¦ foo ™ȁʬł&\àGŚǮ˯“def foo” 1.2. ЫĔ~ - 5 1. đ Cloud9 ɩ‹ }΁ͼƹ 2. ʁ˜“Go to your Dashboard”Ϋ~ǧ§á 3. ζǕ“Create New Workspace”ȇżţ`˓Ϟ 4. ż ê"“rails-tutorial”Ș“rails_tutorial”ʬţ`˓Ϟ¹ζ“Private to the people I invite”? Ōƴσͮʬ=ŽǻʈëζǕ̿ˁ Rails ǿːʬďȾȘ̿ˁ Ruby on Rails τďȾIJď 1.2 ƺˁ 5. ʁ˜“Create” ż 6. Cloud9 ψ̐ţ`˓ϞŁƳëζǕΪţ`˓Ϟʈëʁ˜“Start editing”ŽĶ̋Μ v 1.2w Cloud9 Ý« ž2ĩƞ Ċ"cʡ˓Ʌ̍Ϋ•(Ș Ruby Đιʡʬ˳łƺGƴż͖akǹ̋Μćʬψ̐LjЎ͒ʬĈ˓Ʌǹ "ψ̐ȈɧȘʁ˜ã͌ʬБΖďȾʈëζǕ“Code Editor (Ace)”Ace Eʼ̋Μć̋Μ“Soft Tabs”Η§̿˞̐͝IJď 1.3 ƺˁɩƮkǹ̐͝ë˘ÉʠǽȌϳʁ˜“Save”ǚϒ 6 - Į 1 ī $Ƥ¬‰¶üƑň v 1.3Ţ Cloud9 3ė ĩ÷ŅƇ 1.2.2. ŽŚ Rails ª ̩ żʬŽÔʛĝºñƺȤΗIXɥȤ Rails6 "/ŀ̓ RailsƴHͅcʡº˥ʞć RubyGems ǫe ʬ gem úFđúF̼˼˝όΝ~Eʼɴà 1.1 ƺˁʬúFIJȷđȪĒ˭̃ŽÔđ˼˝˖ÚΝ~ ΪúF IJȷcʡ5˝ IDEđ< cd mv cp rm rmdir rm -rf cat ĥ4 $ ls -l $ mkdir workspace $ cd workspace/ $ cd .. $cd ~ Ƶ $ cd $ cd ~/workspace/ $ mv README.rdoc README.md $ cp README.rdoc README.md $ rm README.rdoc $ rmdir workspace/ $ rm -rf tmp/ $ cat ~/.ssh/id_rsa.pub ˥đȪĒʛĝΩȘđ5˝ IDE  əχȘcʡEʼɴà 1.3ʬúF ż˟ ŷʡɩƮđΪ EʼɴÃƴHȔˀǙł/ Rails ʏȪ4.2.0.beta4Ϊ%sʬʲʬȘˀicʡEʼɴà 1.1ŀ̓ 8 - Į 1 ī $Ƥ¬‰¶üƑň ʬ Rails ʏȪȱ żΪŷʡʬȃIĬ̀ȴǀ̼Eʼɴà 1.3 ʬúFȒIJȷΨĉ“Could not find ’railties”ΪɂʬϖͫͭȔaɥŀ̓ɗˀʬ Rails ʏȪŒɐˀ͒aŀ̓ Rails Ȓǀ̼ʬúFûEʼɴà 1.1 ɏ ɂ 'ĢĉX 1.3¼Ř rails new n(áĤŐđêg $ cd ~/workspace $ rails _4.2.0.beta4_ new hello_app create create README.rdoc create Rakefile create config.ru create .gitignore create Gemfile create app create app/assets/javascripts/application.js create app/assets/stylesheets/application.css create app/controllers/application_controller.rb . . . create test/test_helper.rb create tmp/cache create tmp/cache/assets create vendor/assets/javascripts create vendor/assets/javascripts/.keep create vendor/assets/stylesheets create vendor/assets/stylesheets/.keep run bundle install Fetching gem metadata from https://rubygems.org/.......... Fetching additional metadata from https://rubygems.org/.. Resolving dependencies... Using rake 10.3.2 Using i18n 0.6.11 . . . Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. run bundle exec spring binstub --all * bin/rake: spring inserted * bin/rails: spring inserted IJEʼɴà 1.3 ƺˁǀ̼ rails new úFʠƳƺȤȃI'ëR̢³ǀ̼ bundle install úFƴHRđ 1.3.1 ̩ͭȔΪúFʬ`ʡ ʥƮ  rails new úF żʬȃIûȃIĬΪȾ’ʬȃIĬ̀ȴIJď 1.4Ș Rails ʬOĥP¸' ——͔aBϲŽĶƘκʬ ż àΦ̼ʬˣÃŷʡ̖ƺȤ Rails ŷʡχcʡΪˋȃIĬ̀ȴƺG ϠͯD=ʬEʼȒƑƘŗ̞ʞɴī̅Ϊ8ȃIʬ`ʡIJ̿ 1.2 ƺˁđȪ,ʬë̆ŠňŐ@˽…ħĥ ȁȃIûȃIĬB 5.2.1 ̩ŽĶƴHŐ@˽ app/assets ȃIĬľȘ Asset Pipeline ʬ φšAsset Pipeline Lj˹˻φ̑ CSS û JavaScript ˠ΂ɸȃI׃žŭˣà 1.3. Į ©ė - 9 v 1.4Ý« Rails ©ėĜÛ*…Ŀï ř 1.2Rails Û*…Ŀïİ# Û*/Û*… app/ app/assets bin/ config/ db/ doc/ lib/ lib/assets log/ public/ bin/rails test/ tmp/ 2ė ŷʡʬɃƕȃIºñɏė͉ďǧ§ćûΛ´Ȉɧ ŷʡʬ΂ɸȃIdIJśÙɂƁ̿CSSJavaScript ûďʎ àǀ̼3Ϋ§ȃI ŷʡʬψ̐ ȁǟŶʴƒʬȃI ŷʡʬȃɈ EʼŶɏĖȃI EʼŶʬ΂ɸȃIdIJ CSSJavaScript ûďʎ ŷʡʬȎƗȃI €‚dIJɮ͊ćà͞ϝʬȃIdIJϖͫϷ϶ ʠƳEʼƾŽ˼˝RͦƵó³ȪĒȥ²ćʬːŵ ŷʡʬɭͤ !ȒȃI 10 - Į 1 ī $Ƥ¬‰¶üƑň Û*/Û*… vendor/ vendor/assets README.rdoc Rakefile Gemfile Gemfile.lock config.ru .gitignore 2ė ˟ȈEʼdIJǬIû gem ˟Ȉ΂ɸȃIdIJ CSSJavaScript ûďʎ ŷʡˣ@ cʡ rake úFǀ̼ʬŃʡK² ŷʡƺϳʬ gem gem ̿ˀiΪŷʡʬ®ȪcʡʴéʏȪʬ gem Rack ϞIʬψ̐ȃI Git ƚʦʬȃI 1.3.1. Bundler żŁ ȇʬ Rails ŷʡë əȘcʡ Bundler ŀ̓ûºñͨŷʡƺϳʬ gemđ 1.3 ̩ˣÃǫ¦Σ ǀ̼ rails new úFȒR̢³Φ̼ BundlerιΣ bundle install úFΣΪ ̩ƴHͅkǹŷʡЎ͒ cʡʬ gemʈëŒɐΦ̼ BundlerЄ{đȃȪ̋ΜćƾŽȃI Gemfile̺ʈ†\ʬʏȪäûŠňƵ ͛ȤƺéXħɍEʼɴà 1.4 ûď 1.5 ŦĥΪȃIʬŠňȘ Ruby Eʼʜđ{ƒƕÜ ɧ˟ 4 ˜Rͩ˺@˽ RubyIJȷaɥʶ¦IJď 1.5 ƺˁʬȃIûȃIĬʁ˜ȃIɮ͊ćʬБΖď ȾʈëζǕ“Refresh File Tree”¨ȇȃIɀIJȷɥ—ʜȺȃIƵȃIĬŗàG¨ȇȃIɀ 'ĢĉX 1.4hello_app ƲšĖ¶Ĝ Gemfile source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.0.beta4' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0.0.beta1' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .js.coffee assets and views gem 'coffee-rails', '~> 4.0.0' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: # https://github.com/rails/turbolinks gem 'turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc 1.3. Į ©ė - 11 # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use Rails Html Sanitizer for HTML sanitization gem 'rails-html-sanitizer', '~> 1.0' # Use Unicorn as the app server # gem 'unicorn' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development group :development, :test do # Call 'debugger' anywhere in the code to stop execution and get a # debugger console gem 'byebug' # Access an IRB console on exceptions page and /console in development gem 'web-console', '~> 2.0.0.beta2' # Spring speeds up development by keeping your application running in the # background. Read more: https://github.com/rails/spring gem 'spring' end …Ƒĥ̼Eʼχʡ # ˞äɩϋǢ/Ϊ8EʼǻđΪȘ"/õ͡a 8ŭʡʬ gem*Ș"/Şˁ Bundler ʬÜɧʜđϪ/Ϊ8Ў͒ʬ gem 'ĤƴHΩϳͅ…Dʬ gem IJȷɥđ gem ǙFǙłʏȪäBundler R̢³ȣȇʏ϶ŗȘ d gem 'sqlite3' ΩȤˋŭʡʬȈɧʡȱǙł gem ʏȪʬ̮č łːźǧ§ Rails cʡʬʏȪЄ{ʶ϶Ϊ̼E ʼ gem 'uglifier', '>= 1.3.0' Ϊ̼EʼʬƮƞȘŀ̓ʏȪäħ4Ƶˠ4 1.3.0 ʬȣȇʏ uglifier`ʡȘÌ̍ Asset Pipeline ʬȃ IŗˤȘ 7.2 ʏ*Rŀ̓˟3ˋȈɧIJƺˁ gem 'coffee-rails', '~> 4.0.0' 12 - Į 1 ī $Ƥ¬‰¶üƑň v 1.5wÛêńƀr»¬ƲšĖ¶Ĝ Gemfile Ϊ̼EʼʬƮƞȘŀ̓ʏȪäħ4 4.0.0Xő4 4.1 ʬ coffee-rails*ŗȘͭ>= ˞äʬƮƞȘĶ˼ ŀ̓ȣȇʏ ~> 4.0.0 ʬƮƞȘÞŀ̓̾ ʏȪä×»ʬʏȪdIJB 4.0.0 ¦ 4.0.1̖ŀ̓ɐʏȪ Ƶ#ʏȪʬȠȇdIJB 4.0 ¦ 4.1Σ˾Јõ͡ƴHÉcȘ̾ ʏȪʬÁ˴*à̞Ŏ̤ϖͫƺ GđȪǿːƴHěȪR"ƺȤʬ gem χǙł˫ˀʬʏȪäaàGcʡK] gem ʬȣȇʏȪΩàGđ Gemfile cʡ ~> ̦Ǩ̯Ȥ˾ЈʬʡƹcʡX2{ǫωaΪà̞RŎ̤ȪǿːŽÔʬŷʡ̿ʜž ŭ kǹEʼɴà 1.4 ʬ GemfileǞʡ˫ˀʬʏȪ䃦ʬ̀ȷIJEʼɴà 1.5 ƺˁɩƮnɘȬRƴH Ω׳/ sqlite3 ʬY̐ÞđŽÔʛĝûɭͤʛĝ7.1.1 ̩ŀ̓ς}û Heroku ƺʡʬȁǟŶ˕ 1.5 ̩ 'ĢĉX 1.5ÿ Ruby gem ƒ3ėĴĤđêgĜ Gemfile source 'https://rubygems.org' gem 'rails', '4.2.0.beta4' gem 'sass-rails', '5.0.0.beta1' gem 'uglifier', '2.5.3' gem 'coffee-rails', '4.0.1' gem 'jquery-rails', '4.0.0.beta2' gem 'turbolinks', '2.3.0' gem 'jbuilder', '2.2.3' gem 'rails-html-sanitizer', '1.0.1' gem 'sdoc', '0.4.0', group: :doc 1.3. Į ©ė - 13 group :development, :test do gem 'sqlite3', '1.3.9' gem 'byebug', '3.4.0' gem 'web-console', '2.0.0.beta3' gem 'spring', '1.1.3' end LjEʼɴà 1.5 ʬŠňŽ~ŷʡʬ Gemfile ȃI'ëǀ̼ bundle install úF7 ŀ̓Ϊ8 gem $ cd hello_app/ $ bundle install Fetching source index for https://rubygems.org/ . . . bundle install úFà̞ͅǀ̼ RwΣ̀ȯëƴHʬŷʡŗàGΦ̼/ 1.3.2. rails server Φ̼Ł 1.3 ̩ʬ rails new úFû 1.3.1 ̩ ʬ bundle install úF'ëƴHʬŷʡŗàGΦ̼/XȘ Ɯ%Φ̼÷ Rails ̢ū/ úF̼ːŵƵß̡ȪàGΦ̼ ȪĒȥ²ć´ƴHʬŽÔţ` ΪúF†\Ɯ%ǀ̼Ր4acʡʬʛĝ đȪĒ˭̃ʳǦǀ̼ rails server úFŗ̼Eʼɴà 1.6 ̖đ Cloud9 ῼǙł˿łʬ IP ĒĔû˝Úäõ͡ Rails ȥ²ćĤʤàGιΣÿĒĔ͞ϝŷ ʡEʼɴà 1.78 Cloud9 cʡʒɚʬʛĝ×ώ $IP û $PORT ³ƛǙł IP ĒĔû˝ÚäIJȷƬȼʶΪ ʛĝ×ώʬoàGđúF̼Ν~ echo $IP û echo $PORT 'ĢĉX 1.6wêxŤƃŘ Rails èQr $ cd ~/workspace/hello_app/ $ rails server => Booting WEBrick => Rails application starting on http://localhost:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server 'ĢĉX 1.7wĬ IDE ƃŘ Rails èQr $ cd ~/workspace/hello_app/ $ rails server -b $IP -p $PORT => Booting WEBrick => Rails application starting on http://0.0.0.0:8080 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server ˥cʡÿˋʛĝƴχż͖ađÝ ˼˝ζϹÇǀ̼ rails server úFΪɂaŗàḠ̆đ˟  ζϹÇǀ̼…DúF/IJď 1.6 ûď 1.7 ƺˁIJȷaŨ˾đ˟ ζϹÇó³/ȥ²ćàGǚ Ctrl-C ϗƒϜȥ²ćđȪĒʛĝđɮ͊ćƾŽ http://localhost:3000/ đ5˝ IDE ƾŽ 7. IJ̿ 3.1ƺˁàGʵʦ installĊ" bundle Ș bundle install ʬ¥ê 8. ̦Ƨ‘̏˚cʡ 80 ˝ÚXΪ˝Úϳͅʒ¥ʬȮϨƺG"/ȈgŽÔȥ²ćȣıcʡɥȤϨ§ʬħȁ˝ Ú 14 - Į 1 ī $Ƥ¬‰¶üƑň “Share”š;϶Ȳʁ˜“Application”ëʬĒĔÉàƾŽŷʡIJď 1.8đΪˋʛĝșˁʬϷ϶ ŷͨχûď 1.9 ˨W v 1.6B»¬ ľĬƊƪZ ʁ˜“About your application’s environment”àGȼʶŷʡʬjƣaʶ¦ʬʏȪäà̞ûƴʬ ɂXûď 1.10 Ŧĥƈʈ/BϙάȱʶƴHϳͅΪ Rails Ў͒Ϸ϶Σʜđʶ¦ΪϷ϶ͭȔ Rails àG ɗŭΦ̼/ƴHRđ1.3.4 ̩¢ϪΪϷ϶ȢǞƳƴH̢ŧŽʬЄϷ 1.3. Į ©ė - 15 v 1.7wc ƊƪZƃŘ Rails èQr v 1.8FƃŘwĬž2ĩƞĜêxèQr 16 - Į 1 ī $Ƥ¬‰¶üƑň v 1.9¼Ř rails server n(kĠMĜ Rails ƲšƩƨ v 1.10ƲšƩƨãĥ©ėĜĔ~5µ 1.3. Į ©ė - 17 1.3.3. û{-ŝv-ËNr đ¡ȧϣɛɍ͊  Rails ŷʡʬţ`ȈƁď 1.11ĥŒRȤ8Ŭ´aà̞Ũ˾ɩƮ¦/đ Rails ŷ ʡʬȾ’ȃIĬ̀ȴȤ ȃIĬß app/ď 1.4…ȤĺȃIĬ modelsviews û controllersΪȟˁ Rails ϊʡ/“ɏė-͉ď-ǧ§ć”ˣˎ MVCȹȴɏƁΪˋɏƁLj“ęμΜ”domain logic*ß“²μΜ”business logicďƊʡƹʤ϶ʴƒʬΝ~û̿ʜμΜƆ§šŽđ Web ŷʡ “ęμΜ” ̦Ș“ʡƹ”“ȃ˜”û“Ăü”ˠȁǟɏėGUI žȘɮ͊ćʬ̏Ϸ v 1.11MVC ñïvş û Rails ŷʡ96Ȓɮ͊ćԗ ͮɤrequestWeb ȥ²ćǸ¦Ϊͮɤ'ëՅŚ Rails ŷʡʬ ǧ§ćʢǧ§ćł əͨs>%Ⱥ8Ƨ‘ǧ§ćR˘ÉɷȻ͉ďviewʠƳ HTMLʈë Ôδ́ɮ͊ćŌ4³ƛ̏˚ȱͭȠŭ͆ʬȘǧ§ćûɏėmodel96ɏėȘ  Ruby ŌͶ̿ˁ ̏˚ʬ yˮdIJ ʡƹŲ͸ͺûȁǟŶιjûɏė96ëǧ§ćŒɷȻ͉ďŲLjʠ Ƴʬ HTML Ψĉ́ɮ͊ć IJȷa͋ƒΪ8ŠňȤʁǎͶʡǏƕë϶R˾ŭ͙¦ MVCđ1.3.4 ̩Єɐcʡ MVC ȹȴ̋Ž ŷʡ đ 2.2.2 ̩RG ŷʡ"dΚ"ɱ~Ē͓͜ MVC đȣëτɼˁŷʡRcʡŁȂʬ MVC ȹȴB 3.2 ̩ŽĶ@˽ǧ§ćû͉ď B 6.1 ̩ŽĶ@˽ɏė 7.1.2 ̩žLjΪφšǻđ Έcʡ 18 - Į 1 ī $Ƥ¬‰¶üƑň 1.3.4. Hello, world! ǦȱƴHͅŌΪcʡ MVC ɆȹŽÔʬ˟ ŷʡs8őǹ³——ɳ± ǧ§ć³`ɷȻĻ˞ “hello, world!”B 2.2.2 ̩ŽĶRȠɱ~ʬ@˽ǧ§ć³`Ϊ ̩ʬʲʬȘcʡșˁ“hello, world!” ʬϷ϶ȢǞ Rails Ў͒ʬЄϷď 1.9 B“ǧ§ć³`”ΪêĻàGʶ—³`đǧ§ćł&ƴHͅđ ApplicationController ł&Ϊ³ `ŲՅúê" hello…ŃʜđƴHʬŷʡÞȤ ApplicationController Ϊ ǧ§ćǀ̼϶ʬú FàGЈ͟Ϊ ʁB ˟ 2 ˜ŽĶƴHR ż̢ŧʬǧ§ć $ ls app/controllers/*_controller.rb hello ³`ʬł&\IJEʼɴà 1.8 ƺˁͱʡ render ™ȁΨĉȃȪ“hello, world!”ʜđ{˥ Ruby ʬÜ ɧ˟ 4 ˜Rͩ˺@˽ 'ĢĉX 1.8w ApplicationController ĈP hello R2 app/controllers/application_controller.rb class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception def hello render text: "hello, world!" end end ł&ıΨĉƺϳĻ˞ ʬ³`'ëƴHͅõ͡ Rails cʡΪ³`ŒșˁЎ͒ʬЄϷď 1.10" ɘƴHͅkǹ Rails ΐʢΐʢđǧ§ć'ªď 1.11łɮ͊ćỐŷʡʬͮɤʢÿ³`ġʞ ˣÃΈ͆ď 1.11 ʵʦ/ΐʢB 2.2.2 ̩ŽĶRͩ˺@˽ΐʢ†\̖͏ƴHͅkǹЎ͒ʬЄ Ϸ*ŗȘɄΐʢΪΐʢłɄ URL șˁÿϷ϶Ʉ URL Ș http://www.example.com/ ΪˋƊƁƺ G ̦ˣ»cʡ /ȅ˷̿ˁ IJEʼɴà 1.9 ƺˁRails ŷʡʬΐʢȃIconfig/routes.rbȤ ̼ɩϋͭȔIJ]̋ŽɄΐʢ… “welcome”Șǧ§ćê“index”ȘΪǧ§ćʬ³`êÎǢΪ̼ª϶ʬ # ä͍ϪɩϋΪɂɄΐ ʢŗàGł&/ʈëŒLjŠňȢǞƳEʼɴà 1.10 ʬEʼõ͡ Rails LjɄΐʢ9́ ApplicationController ʬ hello ³`ġʞđ 1.1.2 ̩ͭΣ˙Ǥʬʁä̿ˁʵʦʬEʼͅʳǦģ§ 'ĢĉX 1.9Ė¶ĜƲšöŹĘwĄƔ config/routes.rb Rails.application.routes.draw do . . . # You can have the root of your site routed with "root" # root 'welcome#index' . . . end 1.3. Į ©ė - 19 'ĢĉX 1.10ŤöŹĘ config/routes.rb Rails.application.routes.draw do . . . # You can have the root of your site routed with "root" root 'application#hello' . . . end Ȥ/Eʼɴà 1.8 ûEʼɴà 1.10 ʬEʼɄΐʢŗRǚʉƴHʬͅɤșˁ“hello, world!”/IJď 1.12 ƺ ˁ v 1.12wĆŞróĠãĥ“hello, world!”ĜƩƨ 1.4. 3ė Git 9đêËN ƴHŨ˾ŽÔ/ àGΦ̼ʬ Rails ŷʡǦȱ̪ͅʁȒϞȱs I2̺ʈΪI2ȘƖϻʬXȘ ˾ЈŋʬΗIŽÔ̕χ͒"ΪȘȣěȪʬ2ƧÉLjŷʡʬɸEʼ˶~ʏȪǧ§ʏȪǧ§˭̃àGΎΒ ϹʲEʼʬ×»g4ûD=Â`IJȷ—ʜϝЀdIJőƕ¢Ϫ/ȃIΩàGĉɺ¦GªʬʏȪ ɞ˴ΗIŽÔ̕χŷͨĽ+cʡʏȪǧ§˭̃ 20 - Į 1 ī $Ƥ¬‰¶üƑň ʏȪǧ§˭̃ˋ˨ƑĥRails ˂½ěȪχcʡ GitGit ʢ Linus Torvalds ŽÔȣ¡ʲʬȘļu Linux ŠɃ EʼGit ʴƒʬʺ͠ƑĥȪ,ÞR@˽ 8ʮɡ̏̂ȤƑĥ}΁ʬ΂Ȅƴʒ¥Ǩ̯ Scott Chacon Ž ʬPro Git9 'ƺGǨƆʄǨ̯cʡ Git sʏȪǧ§?Ċ" Rails ˂½χđʡΩĊ"cʡ Git š; EʼȠˣÃ1.4.3 ̩̖*g4ŷʡʬφ̑1.5 ̩ 1.4.1. ŽŚoŤŇ 1.2.1 ̩Ǩ̯cʡʬ5˝ IDE Ў͒Ũ˾ϱƳ GitʡŒŀ̓IJȷaɥcʡ5˝ IDEàGÏʉ InstallRails.com ʬͭȔđ̢ŧʬ˭̃ŀ̓ Git ĮüƃŘOś9ĜĵŁŤŇ cʡGit ªͅs 8 ɐƟ̐͝Ϊ8̐͝ŌȂ˭̃χȤǽĊɘ áʣ̠Þϳ̐͝ ɐ $ git config --global user.name "Your Name" $ git config --global user.email your.email@example.com $ git config --global push.default matching $ git config --global alias.co checkout ɩƮđ Git ψ̐͝łʬêĻûʣĺυIĒĔRđƺȤ€ŽʬCŶșˁª̐͝Ɩϻs˟ ̐͝Ș"/쪉ňȨȱʬ Git ʏȪ˟Ĉ̐͝ȘàζʬIJȷ̐͝/ŗàGcʡ co EȢ checkout ú F"/ȣħːź‰ňɥȤ̐͝ co ʬ˭̃Ȫ,AŐ̄̆cʡê checkoutΣđʜŃƴěȪχʡ git co Įü3ė%¨Oś9ĜŤŇ ϶ʬəЊɞɐȇżCŶȒχͅǀ̼Є{Ϋ~˟ ŷʡʬɄʲƉʈë¡Ķ» ȇCŶ $ git init Initialized empty Git repository in /home/ubuntu/workspace/hello_app/.git/ ʈëǀ̼ git add -A úFLjϹʲʬƺȤȃIχǻ¦CŶ $ git add -A ΪúFRLjƈªʲƉʬƺȤȃIχǻ¦CŶXȘ¼ψʒɚȃI .gitignore ɏƁʬȃIϪĤ rails new úFR̢³ʠƳ εʡ4 Rails Ϲʲʬ .gitignore ȃI̖aΩàGɳ±…DɏƁ10 ±~CŶʬȃI ŽĶY4“Ȟļ½”staging areaΪ ½ʡ4ļǻƐǫ9ʬŠňǀ̼ status úFàG ȼʶȞļ½Ȥÿ8ȃI $ git status On branch master Initial commit Changes to be committed: (use "git rm --cached ..." to unstage) 9. ͣ̕ɩ ȃʏđ˷ϠͯĒĔ http://git-scm.com/book/zh*àGϠͯͣ̕§`ʬʣĺ, https://selfstore.io/products/46 10. Ȫ,ěȪRkǹΪȃIΣ 3.7 ̩ʬЌ˴ɭͤψ̐ɼˁ/IJ]kǹ 1.4. 3ė Git 9đêËN - 21 new file: new file: new file: new file: new file: . . . .gitignore Gemfile Gemfile.lock README.rdoc Rakefile șˁʬŠňƑĥƺGƴcʡ˙Ǥʁäʵʦ/ 8Šň IJȷƬõ͡ Git iʥΪ8ǹ³àGcʡ commit úF $ git commit -m "Initialize repository" [master (root-commit) df0a62f] Initialize repository . . . ȋȾ -m ʬƮƞȘ"Ϊɐǫ9ɳ± ͭȔIJȷɥǙł -m ȋȾGit RƾŽ˭̃Ў͒cʡʬ̋Μć͔ađ …Ν~ͭȔȪ,ƺȤʬˁdχRcʡ -m ȋȾ Ȥ ʁƑύͅͅɩƮ Git ǫ9ÞÔʠđȪĒ*ŗȘͭÞđǀ̼ǫ9ǵ`ʬ͝ĢļuŠň1.4.4 ̩R@ ˽IJ]Ljǹ³Ǩδcʡ git push úF¦άːCŶ Ϻgͭ àGcʡ log úFȼʶǫ9ʬËâ $ git log commit df0a62f3f091e53ffa799309b3e32c27b0b38eb4 Author: Michael Hartl Date: Wed August 20 19:44:43 2014 +0000 Initialize repository IJȷCŶʬǫ9ËâƑĥà̞ϳͅΝ~ q γ— 1.4.2. 3ė Git ç!‡€ IJȷGªBȨʡΣʏȪǧ§ʜđà̞ŁȔʪʏȪǧ§ʬıġτƴ$dĺͭȔ ðqIJaő ƕs/Ⱥǵ`dIJLjύͅʬ app/controllers/ ȃIĬ¢Ϫ/ $ ls app/controllers/ application_controller.rb concerns/ $ rm -rf app/controllers/ $ ls app/controllers/ ls: app/controllers/: No such file or directory ƴHʡ Unix ʬ ls úF— app/controllers/ ȃIĬόʬŠňʈëʡ rm úF¢ϪΪȃIĬȋȾ -rf ʬƮƞȘ“Ɔ§θƇ”ȌϳȔˀƎɤéƮŗθƇ¢ϪƺȤȃIȃIĬûĺȃIĬˠ ȼʶ ʔƛʶʶÔʠ/>% $ git status On branch master 22 - Į 1 ī $Ƥ¬‰¶üƑň Changed but not updated: (use "git add/rm ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) deleted: app/controllers/application_controller.rb no changes added to commit (use "git add" and/or "git commit -a") àGʶ—¢Ϫ/ ȃIXȘΪǹ³ÞÔʠđ“ţ`ɀ”ΩȨǫ9¦CŶƺGƴHàGcʡ checkout úFŲǙł -f ȋȾƆ§dzϕΪɐǹ³ $ git checkout -f $ git status # On branch master nothing to commit (working directory clean) $ ls app/controllers/ application_controller.rb concerns/ ¢ϪʬȃIĬûȃIÐĉȱ/Ϊǻƕ/ 1.4.3. Bitbucket ƴHŨ˾LjϹʲ˶~ Git ʏȪǧ§˭̃/ǦȱàGLjEʼǨδ¦ Bitbucket Bitbucket Ș Ϛʡȱ ƿ˥ûš; Git CŶʬ̏˚Ȫ,ª•ʏcʡ GitHubǞʡ Bitbucket ʬÍĊÏ͆Ȋɩ 1.4đ Bitbucket ǻ L Git CŶʬ®ȪȤʲʬ … ŌEʼsŁȂĢLºǖƺȤǫ9Ëâ …3g4Gë Â` ߥ 1.4GitHub o Bitbucket ʲªƿ˥ Git CŶȣÖɑΥʬ̏˚Ș GitHub û BitbucketΪ̏˚ȤƑĥʴW'ġ χàƿ˥C Ŷ*àGÂ`̖ɮ͊ûǮ˯CŶƑȈgX3̕'ϞȤύͅʬ½¥ŌȪ,̖͏ GitHub " ŽɸϹʲǫeȌϨώʬ}΁CŶXˊȤCŶǸ΁ ̖ Bitbucket ǫe/ȌϨώʬˊȤCŶ?ƈÂ`̕ ΉΣ łȁώȒƼǸ΁ƺGζǕÿ̏˚Ր4†\ʬϳɤ Ȫ,ª•ʏcʡ GitHubĊ"ľŌŽɸϹʲȱͭȤƑĥıʡʬ°̞XƴΊȱΊƒɩŀƺGǨ̯ƺ Ȥ Web ŷʡχǻđˊȤCŶĊ" Web ŷʡʬCŶà̞ºñɽđʬǾƯjƣdIJŊϑûŊʼ à̞Rĸ̛¦cʡΪLEʼʬ̏˚ʬŀƈʈΪ˨jƣ*ȤŀʬġʞȈɧXȘňȕ—ϖ̖ ϳͅƑĥʺ͠ Ȫ,ŽÔʬɼˁŷʡàGŀĒ€ŽXΪÞȘʒd̞ǨŴĊɘ"/ŘώǫЌŀƴH̞ ϫΩȘЎ͒ŗcʡˊȤCŶiϫȍʈ GitHub ŌˊȤCŶǸ΁̖ Bitbucket ǫe/Ϩώʬ}΁ ˊȤCŶŗƴHʬϳɤȱͭBitbucket ɟ Github Ƞèε Bitbucket ʬcʡȈɧƑˣà 1. IJȷɥȤͼƹ{ɩ‹  Bitbucket ͼƹ 2. Lj€ϑģ§¦­›Ȳ5˝ IDE ʡƹàGcʡ cat úFȼʶ€ϑIJEʼɴà 1.11 ƺˁʈëζ€ ϑģ§IJȷađ̢ŧʬ˭̃ǀ̼Eʼɴà 1.11 ʬúFëɥȤΝ—ͮÏʉ“IJ]đaʬ Bitbucket ͼƹ͝ł€ϑ” 1.4. 3ė Git 9đêËN - 23 3. ʁ˜ã͌ʬīvζǕ“Manage account”˥ʞͼƹʈëʁ˜“SSH keys”SSH ŊϑIJď 1.13 ƺˁ v 1.13ĈP SSH =Ƙ 'ĢĉX 1.113ė cat n(»[=Ƙ $ cat ~/.ssh/id_rsa.pub ɳ±€ϑ'ëʁ˜“Create” żǚϒȇż CŶIJď 1.14 ƺˁĜŽϹʲʬjƣȒ͘ƒͅζ “This is a private repository”ΪȘˊȤCŶĜŁëʁ˜“Create repository” żCŶǚϒʈëǚʉ “Command line > I have an existing project”úF̼ > ʜȤϹʲ϶ʬͭȔǵ`IJEʼɴà 1.12 ƺˁ IJȷEʼɴà 1.12 éà̞Ș€ϑɥɗˀɳ±ƴż͖aŒͤ ɐǨδCŶȒIJȷͧϝ“Are you sure you want to continue connecting (yes/no)?”ˀł̄̆ήǦî Ν~“yes” 'ĢĉX 1.12ĈP BitbucketďkÌƉ%¨ $ git remote add origin git@bitbucket.org:/hello_app.git $ git push -u origin --all # ĮüÌƉ%¨ ΪɛEʼʬƮƞȘ{õ͡ GitaƬɳ± Bitbucket`"ΪCŶʬɸʈëŒLjCŶǨδ¦Ϊά˝ʬ ɸ¥˥ -u ȋȾʬƮƞIJȷıĭàGǮ˯“git set upstream”ƈʈ/aͅLj ǞƳa̢ ŧʬʡƹêdIJƴΦ̼ʬúFȘ $ git remote add origin git@bitbucket.org:mhartl/hello_app.git ǨδŁɠëđ Bitbucket Rșˁ  hello_app CŶʬϷ϶đΪϷ϶àGɮ͊ȃIȼʶŁȂʬǫ 9jƣϪɘ'ĤΩȤƑĥ…D°̞IJď 1.15 ƺˁ 24 - Į 1 ī $Ƥ¬‰¶üƑň v 1.14w Bitbucket I«ŒÖƆ ©ėĜ%¨ v 1.15 Bitbucket %¨ĜƩƨ 1.4. 3ė Git 9đêËN - 25 1.4.4. FÔńƀÍh¦ IJȷaΎʹ 1.4.3 ̩ʬəЊsà̞ɩƮ¦/Bitbucket ɥȤ̢³͠¥CŶʬ README.rdoc ȃI̖đC ŶʬЄϷǫωɥȤ README ȃIIJď 1.16 ƺˁΪͭȔ rdoc ɅƁŭ͆ƺG Bitbucket Ƿǘ… ŃƴGÑƴ͒͠ʬ•(ƺȤ=χcʡ Markdown ɅƁΪ ̩ƴHͅLj README.rdoc ȃIǹƳ README.mdϺgῼđ…ɳ± 8ϏŌȪ,ʬŠňđΪΣːƴHŐЄɐɼˁƴǨ̯đ Git cʡ ʬţ`ɬːÉ“šǷ̋Μǫ9èŲ”11 v 1.16Bitbucket ÍĥĂç README Û* FÔ Git ʬšǷ°̞ƑƆħšǷȘŌCŶʬЌǽģ§đšǷƺsʬǹ³Ƶ͛ȘŃЈƟͽʬRƋþ ʌ˴ȃIħĥȁƧ‘ʌ˴CŶȘ master šǷƴHàGcʡ checkout úFŲǙł -b ȋȾ ż ȇ“#ЀšǷ”topic branch $ git checkout -b modify-README Switched to a new branch 'modify-README' $ git branch 11. IJȷƬƊͶ»ʬȼʶ Git CŶàGcʡ Atlassian ŽÔʬŷʡ SourceTree 26 - Į 1 ī $Ƥ¬‰¶üƑň master * modify-README …˟3úF git branch ʬ`ʡȘ—ƺȤȪĒšǷȖä*̿ˁƈªƺđʬšǷɩƮgit checkout -b modify-README úF{ ż ȇšǷʈ댛Ǟ¦ΪȇšǷ——modify-README šǷª϶ʬ Ȗä͟Ȕ/Ϊ ʁIJȷađ 1.4 ̩̐͝/¥ê coŗͅcʡ git co -b modify-README ÞȤĥŽÔ̕Â`ŽÔ ϹʲȒƼ̞ʶ—šǷʬφJo12 IJȷÞȤ ŽÔ̕šǷ*Ȥ`ʡ ̦Ƨ‘ͅLj#ЀšǷʬǹ³û#šǷϮˈŽΪɂÉgǯʾ/ϬȒχàG›Ǟ¦#šǷʈë¢Ϫ #ЀšǷǢǹ³Ȫ̩ȩřR@˽†\sɧ Ϻgͭ vΪˋőǹ³ƴ ̦RȇżšǷʜđƴΪ%sȘ"/͔aˆƳı+ƫ ńƀ ż#ЀšǷëƴH̋ͅΜ README ȃI͔…ȠıĒǪΰƴHʬϹʲΚ'Ў͒ʬ RDoc ɅƁƴȠ ąɑ Markdown Ⱦͪ͘͏IJȷȃIǁŞêȘ .mdBitbucket R̢³Ǥʏ…ʬŠňЄ{cʡ Git ǫeʬ Unix mv úFkǹȃIê $ git mv README.rdoc README.md ʈëLjEʼɴà 1.13 ʬŠňŽ~ README.md 'ĢĉX 1.13Ý README Û*README.md # Ruby on Rails Tutorial: "hello, world!" This is the first application for the [*Ruby on Rails Tutorial*](http://www.railstutorial.org/) by [Michael Hartl](http://www.michaelhartl.com/). Í ̋Μëȼʶ ͨšǷʬʔƛ $ git status On branch modify-README Changes to be committed: (use "git reset HEAD ..." to unstage) renamed: README.rdoc -> README.md Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: README.md ΪόƴHȪàGcʡ 1.4.1.2 ̩ʡΣʬ git add -AXȘ git commit ǫe/ -a ȋȾàGʳǦǫ9ʜȤ ȃIʬφǹ³GÑcʡ git mv ȇżʬȃIŌ Git ȱͭΪˤȇȃI 12. ͩƧÏϠPro Git,“Git šǷ” ˜ 1.4. 3ė Git 9đêËN - 27 $ git commit -a -m "Improve the README file" 2 files changed, 5 insertions(+), 243 deletions(-) delete mode 100644 README.rdoc create mode 100644 README.md cʡ -a ȋȾ łͅőƕÀ¥ͫʡ/IJȷɐǫ9'ëϹʲɳ±/ȇȃIŷͨcʡ git add -A{ õ͡ Git ȇĞ/ȃI ɩƮƴHcʡʜđȒɅȱͭȘ˃cͪɣ̋Žǫ9ɯƣGit Ljǫ9ƈs ˭̾ đΪˋƧ‘ ͭȔʜđs/>%ɟͭȔΣÎs/>%ͅȠèʞ̖Ϊˋʡɧû Git úFʠƳʬǫ9jƣʴψͩƧ ÏϠShiny new commit styles h¦ ƴHŨ˾ǹŁ/ʜđàGLj̀ȷèŲ¦#šǷ/ $ git checkout master Switched to branch 'master' $ git merge modify-README Updating 34f06b7..2c92bef Fast forward README.rdoc | 243 -------------------------------------------------- README.md | 5+ 2 files changed, 5 insertions(+), 243 deletions(-) delete mode 100644 README.rdoc create mode 100644 README.md ɩƮGit úFʬΝ—˾ŭR—ʜ 34f06b7 ΪɂʬĻ˞ ΪȘ Git ŠφŌCŶʬǙEaƒ¦ʬΝ—̀ȷ Rûƴʬ ɏ ɂXħ̤ʴé èŲ'ëƴHàGɴʞ šǷ——IJȷʡΪ#ЀšǷ/àGcʡ git branch -d úFՅ¢Ϫ $ git branch -d modify-README Deleted branch modify-README (was 2c92bef). Ϊ əàsàs…Ń ̦χRʥʹΪ#ЀšǷΪɂŗàGđšǷ'Ϟȱĉ›ǞŲđèεʬȒ mLjǹ³èŲ¦#šǷ ª϶ǫΣΩàGcʡ git branch -D úFǻſ#ЀšǷʬǹ³ # "2čĥėˆðĂÏģVLƆ9 $ git checkout -b topic-branch $ $ git add -A $ git commit -a -m "Major screw up" $ git checkout master $ git branch -D topic-branch ûȋȾ -d éIJȷǙłȋȾ -DÉcɥèŲšǷʬǹ³*R¢ϪšǷ ÌƉ ƴHŨ˾Ƞȇ/ README ȃIʜđàGLjǹ³Ǩδ¦ Bitbucketʶʶǹ³ʬǽȷ'ªƴHŨ˾ǨδΣ ɐ 1.4.3 ̩đħĥȁ˭̃χàGʵʦ origin masterʳǦǀ̼ git push 28 - Į 1 ī $Ƥ¬‰¶üƑň $ git push ɗIJª϶ƺͭBitbucket Ōcʡ Markdown ̋ŽʬȃIs/˫̒ǤʏIJď 1.17 ƺˁ v 1.173ė Markdown ÷­ƕCĜ README Û* 1.5. Ƒň ÉcʜđΩġđȑȧϣɛƴHΩȘͅLj•(ɥ>%Šňʬ Rails ŷʡφ̑¦ʠ:ʛĝΪ əàsà sΣđŽÔΣːŘȑϿ˱Ēφ̑àGŘȑÔʜŽÔʬϝЀđŽÔʛĝ̪΁ħώ˫¯'ë Œφ̑ƍƍRđÔũȒν¦ύʬϱƳϝЀ13 Gªφ̑ Rails ŷʡȘIʨ̬ʬ2XȣΧ•űRails ŽÔʠƛ˭̃ȆƳʊŨ˾—ʜƑĥıʬ͍Ȉ ɇ/ºǖcʡ Phusion PassengerApache û Nginx 14 Web ȥ²ćʬ ɏĖʬ‚;#Ȭû̹ǓˊȤȥ² ćEngine Yard û Rails Machine ΪˋǫeȈYφ̑ȥ²ʬ€åGÑ Engine Yard CloudNinefold û Heroku Ϊˋ5φ̑ȥ² ƴȣąɑcʡ Heroku φ̑ Rails ŷʡHeroku Ϛʡ4φ̑ Rails û…D Web ŷʡφ̑ Rails ŷʡʬΣː žŭˣ×—Þͅɸʼ˶~/ Git ʏȪǧ§˭̃ŗıΪ*Ș">%ͅǚʉ 1.4 ̩@˽ʬəЊ̐͝ GitIJ ȷaΩɥȤʉʹsʜđ·˰sðȪ̩϶ʬŠňϚ@˽IJ]LjƴHʬ˟ ŷʡφ̑¦ Heroku  … 8ǵ`ʴŌЌ˴IJȷɥȤŁʞ͍*ͅ˰Ȫ̩ʬύʁȘLjŷʡφ̑¦˷ʛĝ 13. IJȷaǏƕőƕ€Ž/ŷʡàGÏʉ 1.5.4 ̩ʬsɧΣŌȪ,ŽÔŷʡȱͭΪLǏƕȘĥ^ʬ 14. ͯ`“Engine X” 1.5. Ƒň - 29 1.5.1. Ы Heroku ƑňĔ~ Heroku cʡ PostgreSQL15 ȁǟŶƺGƴHͅLj pg ±~ʠ:˹Ϊɂ Rails Ƽ̞û PostgreSQL ιj 16 group :production do gem 'pg', '0.17.1' gem 'rails_12factor', '0.0.2' end ɩƮƴHΩɳ±/ rails_12factorHeroku cʡΪ gem Vȥϴƛ΂ɸdIJďʎûɂƁ̿ȣ˼ƒ¦ʬ Gemfile IJEʼɴà 1.14 ƺˁ 'ĢĉX 1.14P gem kĜ Gemfile source 'https://rubygems.org' gem 'rails', '4.2.0.beta4' gem 'sass-rails', '5.0.0.beta1' gem 'uglifier', '2.5.3' gem 'coffee-rails', '4.0.1' gem 'jquery-rails', '4.0.0.beta2' gem 'turbolinks', '2.3.0' gem 'jbuilder', '2.2.3' gem 'rails-html-sanitizer', '1.0.1' gem 'sdoc', '0.4.0', group: :doc group :development, :test do gem 'sqlite3', '1.3.9' gem 'byebug', '3.4.0' gem 'web-console', '2.0.0.beta3' gem 'spring', '1.1.3' end group :production do gem 'pg', '0.17.1' gem 'rails_12factor', '0.0.2' end "/’Ģıφ̑ʛĝ϶ͅΦ̼ bundle install úFŲǙł ʒɚʬζϹˆɖđȪĒŀ̓ʠ:ʛ ĝcʡʬ gemÉ pg û rails_12factor $ bundle install --without production Ċ"ƴHđEʼɴà 1.14 Þɳ±/ʡ4ʠ:ʛĝʬ gemƺGʜđǀ̼ΪúF…ŃRđȪĒŀ̓K] ȇʬ gemXȘÐƖϻǀ̼ΪúFĊ"ƴHͅLj pg û rails_12factor ɳ±¦ Gemfile.lock ʈëǫ 9Ϊɐǹ³ $ git commit -a -m "Update Gemfile.lock for Heroku" 15. ͯ` post-gres-cue-ell˾ŭˣˎ Postgres 16. ̦ȱͭŽÔʛĝûʠ:ʛĝͅŘώ ̤ºǖcʡʴéʬȁǟŶXđȪ,ȪĒ ʳcʡ SQLiteʠ:ʛĝžc ʡ PostgreSQLͩƧÏ͆ 3.1 ̩ 30 - Į 1 ī $Ƥ¬‰¶üƑň ǦȱƴHͅɩ‹Ųψ̐  Heroku ȇͼƹ˟ əȘɩ‹ Heroku ͼƹʈëɉȼ˭̃ȘïŨ˾ŀ̓ Heroku úF̼Ņƹ˝ $ heroku version cʡ5˝ IDE ʬͯ̕ŷͨRʶ¦ Heroku Ņƹ˝ʬʏȪäΪ̿ȔàGcʡúF̼ţ† herokuđ…D˭̃ à̞ϳͅcʡ Heroku Toolbelt ŀ̓ ˀ͒ Heroku úF̼ţ†Ũ˾ŀ̓'ëcʡ heroku úFʩƉʈëɳ± SSH Ŋϑ $ heroku login $ heroku keys:add ȣëǀ̼ heroku create úFđ Heroku ʬȥ²ć ż ȃIĬʡ4ļǻɼˁŷʡIJEʼɴà 1.15 ƺˁ 'ĢĉX 1.15w Heroku I« Ý©ė $ heroku create Creating damp-fortress-5769... done, stack is cedar http://damp-fortress-5769.herokuapp.com/ | git@heroku.com:damp-fortress-5769.git Git remote heroku added heroku úFR"aʬŷʡšψ 3˴ęê˘ÉʠǽƈʈʜđΩʶ¦ŠňƴHŽĶφ̑ð 1.5.2. Heroku ƑňĮý φ̑ŷʡʬ˟ əȘcʡ Git Lj#šǷǨδ¦ Heroku  $ git push heroku master (à̞Rʶ¦ 8ǫωɯƣʜđ{˥7.5 ̩R͍) 1.5.3. Heroku ƑňĮý …ŃɥȤ˟3ə/ƴHŨ˾ŁƳφ̑/ʜđàGιΣ heroku create úF́—ʬĒĔÏ͆Eʼɴà 1.15IJȷɥʡ5˝ IDEđȪĒàGǀ̼ heroku open úFȼʶŸŸφ̑ʬŷʡIJď 1.18 ƺˁʶ¦ ʬϷ϶ûď 1.12 ɂXȘʜđΪŷʡΦ̼đʠ:ʛĝ 1.5. Ƒň - 31 v 1.18ƃŘw Heroku ĜĮ ©ė 1.5.4. Heroku n( Heroku ǫe/ƑĥúFȪ,ÞˣÃ@˽/•϶̪•šϐŒ@˽ úF…`ʡȘύúêŷʡ $ heroku rename rails-tutorial-hello a¥ŒcʡΪêĻ/ƴŨ˾Æʡ/Ƶ͛ʜđaȌϳsΪ əcʡ Heroku ǫeʬЎ͒ĒĔŗ̼ ΣIJȷaʷƬύúêŷʡě4ŀ̸̔àGcʡ 8ϬȬƵϯʘ¦ʬ3˴ęêdIJ hwpcbmze.herokuapp.com seyjhflo.herokuapp.com jhyicevg.herokuapp.com cʡΪɂϬȬʬ3˴ęêÞȤaŐĒĔõ͡¥=DHƼ̞͞ϝaʬ̏˚Ϻg͔a ˗ Ruby ʬƆħ ϶ȘƴʡȱʠƳϬȬ3˴ęêʬEʼƑ˫ijð ('a'..'z').to_a.shuffle[0..7].join Ϫ/Ƿǘ3˴ęêHeroku ΩǷǘ̢ł&ęê…ŃȪ,ʬ̏˚17 ŗǻđ Heroku IJȷaϠͯʬȘđ˷ ʏʜđŗđɮ͊ ƿ˥4 Heroku ʬ̏˚đ Heroku ȃɈàGȼʶȠĥƒ4̢ł&ęêʬjƣGÑ Heroku ʴƒʬ…DͦЀ 17. ̭ȃÍʏʬ̏˚ƿ˥đ Heroku aʜđϠͯʬȃʏƿ˥đ Github Pages ĒĔȘ http://railstutorial-china.org 32 - Į 1 ī $Ƥ¬‰¶üƑň 1.6. –Ŀ Ϊ ˜s/Ƒĥ2 ŀ̓ǰżŽÔʛĝʏȪǧ§GÑφ̑ ˜RđΪ ˜ʬěʿŽÔ cʡȁ ǟŶʬŷʡ͔ƴHʶʶ Rails ʷɗʬȪ2 IJȷɘȒaƬš;ϠͯȪ,ʬΫźàGÔ ȰǨȃƵ̕Ƞȇ Facebook ʔƛŽ˨W϶ʬŠň ƴɗđϠͯRuby on Rails ǿːĽ+ Ruby on Rails http://railstutorial-china.org/ ż͖a±~ Rails ǿːυI̿GgÑȒǸ¦Ȫ,ύͅʬȠȇûPƪʼ 1.6.1. ُêīM! • Ruby on Rails Ș cʡ Ruby ̋ːͪ͏ŽÔʬ Web ŽÔɆȹ • đϽ{ψ̐ıʬ5˝ʛĝŀ̓ RailsȇżŷʡGÑ̋ΜȃIχƑˣà • Rails ǫe/úF̼úF railsàʡ4ȇżŷʡrails newûó³ȪĒȥ²ćrails server • ɳ±/ ǧ§ć³`Ųkǹ/Ʉΐʢȣ˼ŽÔ— șˁ“hello, world!”ʬŷʡ • "/ς}Īȁǟ*"/Â`ƴHLjŷʡʬɸʼ˶~ Git ʏȪǧ§˭̖̃ΩLjȣ˼ƒ¦ʬE ʼǨδ¦ Bitbucket ˊȤCŶ • cʡ Heroku Ljŷʡφ̑¦ʠ:ʛĝ 1.7. ļ 1. Lj hello ³`Eʼɴà 1.8ʬ“hello, world!”ǹƳ“hola, mundo!”±šϹ cʡl̐ʬƯæä dIJ“¡Hola, mundo!”ʬ˟ Ļ˞͟Ȕ Rails Ƿǘϵ ASCII Ļ˞18 ̀ȷIJď 1.19 ƺˁ 2. ǚʉ̋Ž hello ³`ʬȈƁEʼɴà 1.8Œɳ± ³`úê" goodbyeɷȻȃȪ“goodbye, world!”ʈëkǹΐʢȃIEʼɴà 1.10LjɄΐʢǹƳ goodbyèȷIJď 1.20 ƺˁ 18. đaʬ̋Μćà̞Rșˁ ɯƣǫˁ“invalid multibyte character”ȌǽʬĥĻ̩Ļ˞¥Î˥ľIJȷaƬ͔Ϊ ɯƣɯĪàGđ͵ɕǮ˯Ϊϖͫɯƣ 1.6. –Ŀ - 33 v 1.196Õ hello R2ãĥÛê“¡Hola, mundo!” v 1.206ÕöŹĘãĥÛê“goodbye, world!” 34 - Į 1 ī $Ƥ¬‰¶üƑň Į 2 ī ē@©ė Ȫ˜ƴHͅŽÔ ˣÃʬɼˁŷʡŞˁ Rails Ɔħʬ°̞ƴHRcʡ̡ƻȹƘκʠƳːŵΪɂŗ̞ ˚đ łЌźɍ͊ Ruby on Rails ̋ːʬΣː*̞ħ̤/͍ Web ŽÔɗIJȊɩ 1.2 ƺͭȪ,Őϊ ʡOéȈɧƓŵɵΫŽÔ ŁȂʬɼˁŷʡν¦ȇʬɍƙχRͩ˺ͭȔΣ"/Ƙκɍ͊* "/ōDžƳŗƯȌϳŌ̡ƻȹς̖ͲƴHàGιΣ URL ûȣ˼ŽÔ—ȱʬʚ†ŷʡ96/͍ Rails ŷʡʬ̀ȴ*˟ ɐɼˁ Rails cʡʬ REST ȹȴ ûë϶ʬɼˁŷʡ˨WΪʚ†ŷʡȤʡƹusersûʡƹʬƔÅmicropostsĊɘˤȘ őėʬ Twitter ˨ŷʡŷʡʬ°̞Ωϳͅë̆ŽÔ̖ŽÔΣːʬƑĥəЊʶΈȱƑ˅ˍΣȞȒʡǏ ƕ B˟ 3 ˜ΈŐBϲŽĶŒŽÔ ˨WʬŁȂŷʡƴΩRǫeħώʬ΂Ȅeë̆ϠͯaͅȤ8̗ ƕͅƝĥʓϖͫȪ˜ʬ#ͅʲʬŗȘ͔á̡ͅƻȹʬ˅ĭαƩ[/̖ͅȠɱ~ʬ/͍ Rails 2.1. ŜG©ė Ϊ ̩ƴH͈ͅœ Ϊʚ†ŷʡû 1.3 ̩ ɂƴH{cʡ rails new úFʠƳŷʡʬЋȹ $ cd ~/workspace $ rails _4.2.0.beta4_ new toy_app $ cd toy_app/ IJȷǀ̼ rails new úFëʶ¦“Could not find “railties””ΪɂʬϖͫͭȔaŀ̓ʬ Rails ʏȪŌŒɐˀ ͒ŀ̓ Rails Ȓǀ̼ʬúFûEʼɴà 1.1 ɏ ɂɩƮIJȷcʡ1.2.1 ̩Ǩ̯ʬ5˝ IDEΪŷʡà Gđ˟ ŷʡƺđʬţ`˓Ϟ żɥƖͅŒȇż ţ`˓ϞIJȷɥʶ¦ȃIàGʁ˜ȃIɮ͊ ćʬБΖďȾʈëζǕ“Refresh File Tree”¨ȇȃIɀ ʈëđȃȪ̋Μćkǹ GemfileŽ~Eʼɴà 2.1 ʬŠň 'ĢĉX 2.1Ɔ ē@©ėĜ Gemfile source 'https://rubygems.org' gem 'rails', '4.2.0.beta4' gem 'sass-rails', '5.0.0.beta1' gem 'uglifier', '2.5.3' gem 'coffee-rails', '4.0.1' gem 'jquery-rails', '4.0.0.beta2' gem 'turbolinks', '2.3.0' gem 'jbuilder', '2.2.3' gem 'rails-html-sanitizer', '1.0.1' gem 'sdoc', '0.4.0', group: :doc group :development, :test do gem 'sqlite3', '1.3.9' gem 'byebug', '3.4.0' gem 'web-console', '2.0.0.beta3' gem 'spring', '1.1.3' 35 end group :production do gem 'pg', '0.17.1' gem 'rails_12factor', '0.0.2' end ɩƮEʼɴà 2.1 ûEʼɴà 1.14 ʬŠň ɂ û 1.5.1 ̩ ɂŀ̓ gem ȒͅǙł --without production ζϹŀ̓ʠ:ʛĝƺϳʬ gem $ bundle install --without production ȣëLjΪʚ†ŷʡ˶~ Git ʏȪǧ§˭̃ $ git init $ git add -A $ git commit -m "Initialize repository" aΩàGđ Bitbucket ̏˚ʁ˜“Create”ȇżǚϒ ż ȇCŶď 2.1ʈëLjEʼǨδ¦Ϊά ːCŶ $ git remote add origin git@bitbucket.org:/toy_app.git $ git push -u origin --all # ƮüÌƉƆ %¨ v 2.1w Bitbucket Ɔ ē@©ėI« %¨ Ίȑφ̑ŷʡΊıƴż͖LjEʼɴà 1.8 ûEʼɴà 1.9 ʬŠňģ§Σȱ1 ʈëǫ9ǹ³ŒǨδ¦ Heroku 36 - Į 2 ī ē@©ė $ git commit -am "Add hello" $ heroku create $ git push heroku master û 1.5 ̩ ɂà̞Rʶ¦ 8ǫωɯƣʜđ{Î˥ľ7.5 ̩R͍Ϫ/ Heroku "ŷʡǫeʬ ĒĔ'ĤΝ—ʬŠňŷͨûď 1.18 ɂ ϶ͅŽÔΪŷʡ/ ̦ȱͭŽÔ Web ŷʡʬ˟ əȘ żȁǟɏėdata modelɏė̿ˁŷʡ ƺϳʬ̀ȴΪʚ†ŷʡȘƔÅŅÞȤʡƹûˣʻʬȃ˜ƔÅτ%ƴH{"Ϊŷʡɳ±ʡƹ ɏė2.1.1 ̩ʈëŒɳ±ƔÅɏė2.1.2 ̩ 2.1.1. ė¸û{ ̏̂ȤĥŒéʬɩ‹̿ÃŗȤĥŒł&ʡƹȁǟɏėʬȈƁƴHͅcʡ ˋȣˣÃʬΪʚ†ŷ ʡʬʡƹȤ ā ʬȾ͠ idinteger ˨ė €ŽʬêĻ namestring ˨ėGÑ ʣĺυI ĒĔ email*Ș string ˨ėʣĺυIĒĔ*`"ʡƹêcʡʡƹɏėʬ̀ȴIJď 2.2 v 2.2ė¸ÙÇû{ đ 6.1.1 ̩Rʶ¦ď 2.2 ʬ users Ōŷ4ȁǟŶʬ ̿ idname û email Ș̿ʬ 2.1.2. ±Yû{ ƔÅȁǟɏėʬɃƕɟʡƹɏėῼˣà ƔÅÞͅ  id û̿ˁƔŊňʬ contenttext ˨ėĻɛÉ à2 ΣΩȤ ɟΚģȭʬĻɛͅŃʜΪĻɛLjƔÅûʡƹƒ̘ΈȱƴHcʡ user_id ļuƔÅʬ ş#ȣ˼ƒ¦ʬƔÅȁǟɏėIJď 2.3 ƺˁ v 2.3±YÙÇij{ 2.3.3 ̩R@˽Ɯɂcʡ user_id ĻɛˣÃʬŃʜ ʡƹǔȤĥƔÅʬ°̞đ˟ 11 ˜ȤȠŁȂʬͭ Ȕ 1. 'ƺGΪ%sȘĊ"Rails ǫeʬЎ͒Ϸ϶đ Heroku ̞ɗŭșˁĊɘƑϯ£Ȇφ̑ȘïƳ° 2. ƔÅʬŠňƑʻstring ˨ėŗΌĦ/Xcʡ text ˨ėȠ̞̿ȔƴHʬƮď̖*g4GëǻʼnƔÅϙźϨ§ 2.1. ŜG©ė - 37 2.2. ė¸ŵċ Ϊ ̩ƴHͅŃʜ 2.1.1 ̩͝łʬʡƹȁǟɏėΩR"Ϊɏė ż Web ʤ϶3̀̕èΈȱŗȘ “ʡ ƹ΂ɸ”Users Resource“΂ɸ”ʬƮƞȘLjʡƹ͝Ƭ"ŌͶàGιΣ HTTP Â͖đ̏Ϸ żcreateͯÕreadȠȇupdateû¢ϪdeleteɗIJª϶ǫ¦ʬʡƹ΂ɸcʡ Rails Š̐ʬ̡ƻȹ ʠƳƴż͖a{ͅ˺ʶ̡ƻȹʠƳʬEʼΪȒʶÞR͔aȠČƩ Lj scaffold Ś rails generate ŗàGcʡ Rails ʬ̡ƻȹ/Ś scaffold ʬÏȁȘ΂ɸêʬÃȁƊƁ ΪόȘ User3 ë϶àGŒΎʹ 8àζÏȁǙłȁǟɏėʬĻɛ $ rails generate scaffold User name:string email:string invoke active_record create db/migrate/20140821011110_create_users.rb create app/models/user.rb invoke test_unit create test/models/user_test.rb create test/fixtures/users.yml invoke resource_route route resources :users invoke scaffold_controller create app/controllers/users_controller.rb invoke erb create app/views/users create app/views/users/index.html.erb create app/views/users/edit.html.erb create app/views/users/show.html.erb create app/views/users/new.html.erb create app/views/users/_form.html.erb invoke test_unit create test/controllers/users_controller_test.rb invoke helper create app/helpers/users_helper.rb invoke test_unit create test/helpers/users_helper_test.rb invoke jbuilder create app/views/users/index.json.jbuilder create app/views/users/show.json.jbuilder invoke assets invoke coffee create app/assets/javascripts/users.js.coffee invoke scss create app/assets/stylesheets/users.css.scss invoke scss create app/assets/stylesheets/scaffolds.css.scss ƴHđǀ̼ʬúF±~/ name:string û email:stringΪɂŗàGŃʜď 2.2 ʬʡƹɏė/ɩƮɥ ƖͅǙł id ĻɛRails R̢³ żŲՅ͝"̿ʬ#ϗprimary key ǦȱƴHͅʡ RakeÏ͆Ȋɩ 2.1ȱΡˏmigrateȁǟŶ 3. ̡ƻȹcʡʬêĻûɏė ̤ȘÃȁ ̖΂ɸûǧ§ćcʡģȁĊɘΪόͅcʡ UserȘ Users 38 - Į 2 ī ē@©ė $ bundle exec rake db:migrate == CreateUsers: migrating ============================================== -- create_table(:users) -> 0.0017s == CreateUsers: migrated (0.0018s) ===================================== ϶ʬúFRcʡȇł&ʬʡƹȁǟɏėȠȇȁǟŶ6.1.1 ̩Rͩ˺@˽ȁǟŶΡˏɩƮ"/cʡ Gemfile Ǚłʬ Rake ʏȪƴHͅιΣ bundle exec ǀ̼ rakeđƑĥ˭̃ºǖ5˝ IDEχƖc ʡ bundle execXȺ8˭̃ƖϻcʡƺG"/úFʬŁȂƴR ʳcʡ bundle exec ʈëǀ̼϶ʬúFđÝ ζϹÇΦ̼ȪĒ Web ȥ²ćď 1.7 4 $ rails server -b $IP -p $PORT # wêxŤdƥ¼Ř `rails server` ʜđΪʚ†ŷʡŷͨàGιΣȪĒȥ²ć͞ϝ/1.3.2 ̩IJȷcʡ5˝ IDEͅđ ȇʬɮ͊ć ζϹÇƾŽ̏Ϸ¥đ IDE ƾŽ ߥ 2.1Rake đ Unix Ljɸʼ̋ͣƳàǀ̼ʬːŵȒmake ǃɼ/Ƒύͅʬ̨͌ƑĥːŵöʬΓ\ʟ̣Ũ˾Ō ϶ʬEʼ:ʠ/ȰIÓŏ $ ./configure && make && sudo make install đ Unix ºǖ Linux û Mac OS XΪúF ̦ʡȱ̋ͣEʼ Rake Ș Ruby ʏʬ makeʡ Ruby ͪ͏̋Žʬ˨ make ːŵRails ɿɫʬΦʡ/ Rake ʬ°̞ǫe/ ƑĥŽÔě4ȁǟŶʬ Web ŷʡƺϳʬ˥ʞK²rake db:migrate Ƶ͛ȘȣŭʡʬϪɘ'ĤΩȤƑ ĥ…DúFΦ̼ rake -T db àGȼʶƺȤȁǟŶʴƒʬK² $ bundle exec rake -T db IJȷƬȼʶƺȤ Rake K²Φ̼ $ bundle exec rake -T K²̿ʶΈȱȤʁ͔=Dzʹī̠ΣʜđȌϳǏƕaϳͅʺοƺȤʟ̣ħĥȁúFĽ ŁȪǿːëaRʺοƺȤύͅʬK² 2.2.1. ĆŞė¸Ğ>ĜƩƨ IJȷ͞ϝɄ URL http://localhost:3000/ ʶ¦ʬΩȘ Rails Ў͒Ϸ϶ď 1.9Σcʡ̡ƻȹʠƳʡƹ΂ɸȒ ʠƳ/ƑĥʡȱġʞʡƹʬϷ϶dIJ—ƺȤʡƹʬϷ϶ĒĔȘ /users żȇʡƹʬĒĔȘ /users/ newȪ̩ʬʲʬŗȘΆЅ͇̪Ēɮ͊ Ϊ8ʡƹʴƒʬϷ϶ɮ͊ȒaRÔʜ̿ 2.1 ƑȤʡ̿șˁ/ Ϸ϶û URL 'ϞʬŌŷƒ˭ 4. rails ̡Ȫ˾ΣʒɚġʞȌϳcʡ bundle exec 2.2. ė¸ŵċ - 39 ř 2.1ė¸ŵċƩƨo URL Ĝ”©>ĵ URL R2 /users index /users/1 show /users/new new /users/1/edit edit 2ė —ƺȤʡƹ șˁ ID " 1 ʬʡƹ żȇʡƹ ̋Μ ID " 1 ʬʡƹ ƴH{ȱʶ șˁƺȤʡƹʬϷ϶ΪϷ϶ß“˯ƂϷ”ûϽȧ ɂʲªΩɥȤʡƹIJď 2.4 ƺ ˁ v 2.4ė¸ŵċĜķ®Ʃ/users IJȷƬ żȇʡƹ͞ͅϝ“ȇżʡƹ”Ϸ϶IJď 2.5 ƺˁđȪĒŽÔȒĒĔʬª϶φšχȘ http://localhost:3000 Ƶ5˝ IDE šψʬĒĔĊɘđë϶ʬŠňƴRʵʦΪ φš˟ 7 ˜RLjΪϷ ϶ǹλƳʡƹɩ‹Ϸ϶ ƴHàGđ̿ÃĜ~êĻûʣĺυIĒĔʈëʁ˜“Create User” żʡƹǚϒ ż ʡƹʈë ŗRșˁΪʡƹʬϷ϶IJď 2.6 ƺˁϷ϶șˁʬ̨̉ȃĻȘ“ϛʜɯƣ”flash message7.4.2 ̩R @˽ɩƮΪϷ϶ʬ URL Ș /users/1aà̞ʘ¦/Ϊόʬ 1 ŗȘď 2.2 ʬʡƹ id7.1 ̩RLjΪ Ϸ϶ƾλƳʡƹʬ΂ȄϷ 40 - Į 2 ī ē@©ė v 2.5Ý«ė¸Ʃƨ/users/new v 2.6ãĥò ė¸ĜƩƨ/users/1 2.2. ė¸ŵċ - 41 IJȷƬkǹʡƹʬjƣ͞ͅϝ“̋ΜϷ϶”ď 2.7kǹʡƹjƣëʁ˜“Update User”Ƞȇʡƹǚϒ ŗȠǹ/Ϊʚ†ŷʡͨʡƹʬjƣď 2.8˟ 6 ˜Rͩ˺@˽ʡƹʬjƣļuđë˝ʬȁǟŶ ƴHRđ 9.1 ̩"ɼˁŷʡɳ±̋ΜûȠȇʡƹjƣʬ°̞ v 2.7ńƀė¸5µĜƩƨ/users/1/edit ʜđĉ¦ żȇʡƹʬϷ϶ǫ9̿à ż˟3ʡƹʈë͞ϝʡƹ˯ƂϷ̀ȷIJď 2.9 ƺˁ7.1 ̩R ̒»ΪșˁƺȤʡƹʬϷ϶ ƴHŨ˾ʶ/ żșˁû̋ΜʡƹʬϷ϶ȣëͅʶ¢ϪʡƹʬϷ϶ď 2.10ʁ˜ď 2.10 ƺˁʬϔ ǦëR¢Ϫ˟3ʡƹ˯ƂϷ϶ŗÞ¬ ʡƹ/IJȷΪǵ`Ƴ°ˀ͒ɮ͊ćȘïóʡ/ JavaScriptRails ιΣ JavaScript ÔΈ¢Ϫʡƹʬͮɤ9.4 ̩R"ɼˁŷʡŃʜʡƹ¢Ϫ°̞̖?Ϩ4 ˥ʞö˴¥ʬʡƹƼ̞ǀ̼ΪϹǵ` 42 - Į 2 ī ē@©ė v 2.8åÝ5µkĜė¸Ʃƨ v 2.9I«Į ė¸kĜė¸ķ®Ʃ/users 2.2. ė¸ŵċ - 43 v 2.10KƢ ė¸ 2.2.2. MVC ‘· ƴHŨ˾Ƙκɍ͊/ʡƹ΂ɸ϶ƴHB MVC1.3.3 ̩ʬ͉͌—Ôń͉…Ⱥ8ʒłφšƴHͅ šȵđɮ͊ć͞ϝʡƹ˯ƂϷʬΣː/͍  MVCď 2.11 ďçəʬͭȔIJ 1. ɮ͊ćì /users ÔΈ ͮɤ 2. Rails ʬΐʢLj /users 9́ UsersController ʬ index ³`ġʞ 3. index ³`ͅɤʡƹɏėͯÕƺȤʡƹUser.all 4. ʡƹɏėBȁǟŶͯÕƺȤʡƹ 5. ʡƹɏėLjƺȤʡƹ˹Ƴʬ̿Ψĉ́ǧ§ć 6. ǧ§ćLjƺȤʡƹ΃ó @users ×ώʈëS~ index ͉ď 7. ͉ďcʡš~Ɓ Ruby LjϷ϶ɷȻƳ HTML 8. ǧ§ćLj HTML Ôδĉɮ͊ć5 5. Ȥ8ȃ˜͉ͭďʳǦLj HTML Ψĉ́ɮ͊ćιΣ Web ȥ²ćdIJ Apache Ƶ Nginx˥Ńʜʬ˺̩IJ]ƴȠʴj ǧ§ćȘ ȸŷʡƺȤjƣχR˾ʢľSθ 44 - Į 2 ī ē@©ė v 2.11Rails Ĝ MVC ñïũş ϶ͩ˺šȵΪΣːЄ{Bɮ͊ćÔΈ ͮɤ˟ 1 əàGʳǦđɮ͊ćĒĔȿΝ~Ē Ĕ*àGʁ˜̏ϷʬϔǦͮɤ¦Π Rails ΐʢ˟ 2 əɄǟ URLGÑͮɤʬ˨ėÏ͆Ȋɩ 3.2ՅšỐèεʬǧ§ć³`Ljʡƹ΂ɸʴƒʬ URL ȗŏ¦ǧ§ć³`ʬEʼIJEʼɴà 2.2 ƺ ˁΪ̼EʼRǚʉ̿ 2.1 ʬŌŷƒ˭sȗŏ:users Ϊ˞äƑĭƠľȘ ˞äSymbol4.3.3 ̩R@˽ 'ĢĉX 2.2Rails ŹĘ?ė¸ŵċĜŜH config/routes.rb Rails.application.routes.draw do resources :users . . . end ȍʈƾŽ/ΐʢȃIτŗ̪ʁwȒϞLjɄΐʢǹ"ʡƹ˯ƂϷðkǹ'ë͞ϝɄĒĔŗRșˁ /users Ϸ϶đEʼɴà 1.10 ƴHLj 2.2. ė¸ŵċ - 45 # root 'welcome#index' ǹƳ/ root 'application#hello' ͔ɄΐʢǙì ApplicationController ʬ hello ³`ʜđƴHƬcʡ UsersController ʬ index ³` ͅǚʉEʼɴà 2.3 ƺˁʬȈƁkǹIJȷȪ˜Žīđ ApplicationController ɳ±/ hello ³`ƴż͖ ʜđLjΪ³`¢Ϫ 'ĢĉX 2.3ÀöŹĘÅl UsersController ĜR2 config/routes.rb Rails.application.routes.draw do resources :users root 'users#index' . . . end 2.2.1 ̩ɮ͊ʬϷ϶Ōŷ4 UsersController ʬé³`̡ƻȹʠƳʬǧ§ćEʼDZͅIJEʼɴà 2.4 ƺˁɩƮ class UsersController < ApplicationController ΪˋŽɧđ Ruby ̿ˁ˨̄dž2.3.4 ̩R ˣͅ@˽̄dž4.4 ̩Œsͩ˺@˽ 'ĢĉX 2.4ė¸ËNr'ĢÑś app/controllers/users_controller.rb class UsersController < ApplicationController . . . def index . . . end def show . . . end def new . . . end def edit . . . 46 - Į 2 ī ē@©ė end def create . . . end def update . . . end def destroy . . . end end aà̞ɩƮ¦/³`ʬȁώɟƴHʶΣʬϷ϶ȁώĥindexshownew û edit Ōŷ4 2.2.1 ̩@˽ʬϷ ϶ΣΩȤ 8…D³`createupdate û destroy ˠΪ8³` ̦ʳǦɷȻϷ϶ΣȤȒ* RÞRkǹȁǟŶiļʬʡƹȁǟ̿ 2.2 —/ǧ§ćʬφ³`Ϊ8³`ŗȘ Rails Ō REST ȹ ȴÏ͆Ȋɩ 2.2ʬŃʜREST ȹȴʢ͑ˤȬˌĽŇ Roy Fielding ǫ—ƮƞȘ“̿ʜśʔƛΕ »”Representational State Transfer6 ɩƮ̿ 2.2 ʬŠňȤ8φšȤύÙdIJ show û update ³ `χȗŏ¦ /users/1 ΪĒĔ3̕ʬ½¥Șcʡʬ HTTP ͮɤȈɧé3.3 ̩RȠͩ˺Ē@˽ HTTP ͮɤȈɧ ř 2.2'ĢĉX 2.2 Ė¶Ĝĭh REST ñïĜŹĘ HTTP ŭā URL R2 2ė GET /users index —ƺʡʡƹ GET /users/1 show șˁ ID " 1 ʬʡƹ GET /users/new new șˁ żȇʡƹϷ϶ POST GET PATCH DELETE /users /users/1/edit /users/1 /users/1 create edit update destroy żȇʡƹ șˁ̋Μ ID " 1 ʬʡƹϷ϶ Ƞȇ ID " 1 ʬʡƹ ¢Ϫ ID " 1 ʬʡƹ 6. ±ŢħĽɒȃšɁ 2000 ű Roy Thomas Fielding ʬÅğ͜ȃArchitectural Styles and the Design of Network-based Software Architectures 2.2. ė¸ŵċ - 47 ߥ2.2řĕ›Ē³żUREST IJȷaϠͯΣ 8 Ruby on Rails Web ŽÔʴƒʬ΂ȄRʶ¦ƑĥĒȈχǫ¦/“REST”ľȘ“̿ʜś ʔƛΕ»”REpresentational State TransferʬˣˎREST Ș ˋȹȴȈƁʡȱŽÔšũƁě4̏ ̂ʬ˭̃ûΗIːŵdIJ WWW û Web ŷʡREST ʞ͜ƑǎͶđ Rails ŷʡREST Ʈøʹħ ĥȁ˹IdIJʡƹûƔÅχŔɏė»×Ƴ΂ɸresourceàG żcreateͯÕ readȠȇupdateû¢ϪdeleteΪ8ǵ`ƒ˭ėȁǟŶʬ CRUD ǵ`û HTTP ͮɤȈ ɧPOSTGETPATCH 7 û DELETEŌŷ3.3 ̩ʒ¥ȘȊɩ 3.2ŐȠͩ˺Ē@˽ HTTP ͮɤ `" Rails ŷʡŽÔ̕REST ŽÔȈƁ̞Ŭ´ał̋Žÿ8ǧ§ćû³` aÞϳˣÃʬLjàG żͯÕȠȇû¢Ϫʬ΂ɸʞɴŗàG/ŌȪ˜ʬ“ʡƹ”û“ƔÅ”ȱͭΪ ΣːϵŭȔˀĊ" ľHχȘƑ̢ʈʬ΂ɸƊƁđ˟ 12 ˜Őʶ¦cʡ REST ȹȴàGιΣ ˋ̢ʈ̖gǠʬȈƁ͍Ƒ ɋƻʬϝЀ“ƒɩʡƹ”°̞ "/ǥȔʡƹǧ§ćûʡƹɏė'Ϟʬƒ˭ƴHʶ ˣ»ëʬ index ³`IJEʼɴà 2.5 ƺˁ̡ ƻȹʠƳʬEʼƑ˩ˬƺGƴs/ˣ» 'ĢĉX 2.5Ɔ ē@©ėİUkĜ index R2 app/controllers/users_controller.rb class UsersController < ApplicationController . . . def index @users = User.all end . . . end index ³`Ȥ ̼Eʼ@users = User.allď 2.11 ʬ˟ 3 əͅɤʡƹɏėBȁǟŶ՗ƺȤʡ ƹ˟ 4 əʈëLj̀ȷ΃ó @users ×ώͯ`“at-users”˟ 5 əʡƹɏėʬEʼÏ͆Eʼɴà 2.6EʼʶWˣÃXȘιΣ̄dž†Ģ/Ƒĥ°̞Ï͆ 2.3.4 ̩ û 4.4 ̩†\̖͏ͱʡ Rails ʬ Active Record ŶëUser.all ŗ̞̰ÕȁǟŶʬƺȤʡƹ 'ĢĉX 2.6ē@©ėĜė¸û{ app/models/user.rb class User < ActiveRecord::Base end ł& @users ×ώëǧ§ćŒͱʡ͉ď˟ 6 ə͉ďʬEʼIJEʼɴà 2.7 ƺˁG @ Žīʬ×ώȘ “Ńd×ώ”instance variableđ͉ď̢³àʡđȪdindex.html.erb ͉ďʬEʼEʼɴà 2.7ξË @users"ɞʡƹʠƳ ̼ HTMLaʜđà̞ͯƲΪ8EʼΪόÞȘ͔aʶ ͉ďE ʼȘ>%ɂĺ 7. Rails ȑȧʏȪcʡ PUT ͮɤȠȇȁǟXȘɄǟ HTTP Ⱦ’PATCH ȈɧȠèε 48 - Į 2 ī ē@©ė 'ĢĉX 2.7ė¸ķ®ƩĜŝv'Ģ app/views/users/index.html.erb

    Listing users

    <% @users.each do |user| %> <% end %>
    Name Email
    <%= user.name %> <%= user.email %> <%= link_to 'Show', user %> <%= link_to 'Edit', edit_user_path(user) %> <%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %>

    <%= link_to 'New User', new_user_path %> ͉ďLjEʼΕǞƳ HTML˟ 7 əʈëǧ§ćՅΨĉ́ɮ͊ćŒșˁ—ȱ˟ 8 ə 2.2.3. Ɔ ė¸ŵċĜ ŷ ̡ƻȹʠƳʬʡƹ΂ɸ̺ʈ̞Ħ͔aħ̤/͍ RailsX*Ȥ 8Ό • ɥЈ͟ȁǟʡƹɏėRǦÖ˓êĻûȌǽʬʣĺυIĒĔ̖Njϖ • ɥȤ͒͟Ȭ§ɥŃʜʩƉûγ—°̞ϬƮ ʡƹχàGΫ̼K]ǵ` • ɥȤɭͤ*ȘŁɥȤ̡ƻȹRʠƳ 8ěȪʬɭͤΣƑ˩ˬ*ɿgɥȤϏŌȁǟЈ ͟û͒͟ʬɭͤȠ¥ͭϏŌ…D°̞ʬɭͤ/ • ɥɂƁɥũŚɥȤ‚ʡʬɂƁû̏˚Ŏ̥ • ɥʷɗʞ͍IJȷa̞ͯƲ̡ƻȹʠƳʬEʼŗϳͅϠͯΪȪ,/ 2.3. ±Yŵċ ƴHŨ˾ʠƳŲɮ͊/ʡƹ΂ɸʜđͅʠƳƔÅ΂ɸϠͯȪ̩ȒƴǨ̯aû 2.2 ̩Ōɟ aRÔ ʜ΂ɸđƑĥȈ϶χȘ ̤ʬιΣΪɂύģʠƳ΂ɸƴHàGȠıĒʞ͍ Rails ʬ REST ȹȴđ Ϊɂʬȑȧϣɛʶ ʡƹ΂ɸûƔÅ΂ɸʬʴé'ġ*ȘȪ˜ʬ#ͅʲʬ'  2.3. ±Yŵċ - 49 2.3.1. ùޱYŵċ ûʡƹ΂ɸ ɂƴHcʡ rails generate scaffold úFʠƳƔÅ΂ɸʬEʼΣΪ ɐͅŃʜď 2.3  ʬȁǟɏė 8 $ rails generate scaffold Micropost content:text user_id:integer invoke active_record create db/migrate/20140821012832_create_microposts.rb create app/models/micropost.rb invoke test_unit create test/models/micropost_test.rb create test/fixtures/microposts.yml invoke resource_route route resources :microposts invoke scaffold_controller create app/controllers/microposts_controller.rb invoke erb create app/views/microposts create app/views/microposts/index.html.erb create app/views/microposts/edit.html.erb create app/views/microposts/show.html.erb create app/views/microposts/new.html.erb create app/views/microposts/_form.html.erb invoke test_unit create test/controllers/microposts_controller_test.rb invoke helper create app/helpers/microposts_helper.rb invoke test_unit create test/helpers/microposts_helper_test.rb invoke jbuilder create app/views/microposts/index.json.jbuilder create app/views/microposts/show.json.jbuilder invoke assets invoke coffee create app/assets/javascripts/microposts.js.coffee invoke scss create app/assets/stylesheets/microposts.css.scss invoke scss identical app/assets/stylesheets/scaffolds.css.scss IJȷʶ¦ Spring ʴƒʬϖͫŒɐǀ̼ΪúFÉà ʈëû 2.2 ̩ ɂƴHͅǀ̼ΡˏȠȇȁǟŶcʡȇżʬȁǟɏė $ bundle exec rake db:migrate == CreateMicroposts: migrating =============================================== -- create_table(:microposts) -> 0.0023s == CreateMicroposts: migrated (0.0026s) ====================================== 8. ûʠƳʡƹ΂ɸcʡʬ̡ƻȹúF ɂʠƳƔÅ΂ɸʬ̡ƻȹ*ͅcʡÃȁƊƁĊɘͅʡ generate Micropost 50 - Į 2 ī ē@©ė ʜđƴHŗàGcʡ˨W 2.2.1 ̩@˽ʬȈɧȱ żƔÅ/aà̞ʘ¦/̡ƻȹΩRȠȇ Rails ʬΐʢ ȃI"ƔÅ΂ɸ±~ Ȱ͈žIJEʼɴà 2.8 ƺˁ9 ûʡƹ΂ɸ˨Wresources :micropsts LjƔÅʴ ƒʬ URL ȗŏ¦ MicropostsControllerIJ̿ 2.3 ƺˁ 'ĢĉX 2.8Rails ĜŹĘçíƗ”±YŵċĜÝŜH config/routes.rb Rails.application.routes.draw do resources :microposts resources :users . . . end ř 2.3'ĢĉX 2.8 ±YŵċĖ¶Ĝĭh REST ñïĜŹĘ HTTP ŭā URL R2 2ė GET /microposts index —ƺȤƔÅ GET /microposts/1 show șˁ ID " 1 ʬƔÅ GET /microposts/new new șˁ żȇƔÅʬϷ϶ POST /microposts create żȇƔÅ GET /microposts/1/edit edit șˁ̋Μ ID " 1 ʬƔÅϷʼ PATCH DELETE /microposts/1 /microposts/1 update destroy Ƞȇ ID " 1 ʬƔÅ ¢Ϫ ID " 1 ʬƔÅ MicropostsController ʬEʼˣ»ëIJEʼɴà 2.9 ƺˁɩƮϪ/Lj UsersController ǞƳ MicropostsController 'ĤΪɛEʼûEʼɴà 2.4 ɥ>%½¥ΪͭȔ/΂ɸđ REST ȹȴʬ‚é' ġ 'ĢĉX 2.9İUkĜ MicropostsController app/controllers/microposts_controller.rb class MicropostsController < ApplicationController . . . def index . . . end def show . 9. ̡ƻȹʠƳʬEʼûEʼɴà 2.8 ʴɟà̞RȤЁĤʬ˓̼ȌϻǏƕĊ" Ruby RƚʦЁĤʬ˓̼ 2.3. ±Yŵċ - 51 . . end def new . . . end def edit . . . end def create . . . end def update . . . end def destroy . . . end end ƴHđÔũƔÅʬϷ϶/microposts/newΝ~ 8ŠňÔũ ˦ƔÅIJď 2.12 ƺˁ ȍʈŨ˾ƾŽΪϷ϶/τŗĥÔũ•˦ƔÅŲˀịŒLj ˦ƔÅʬ user_id ͝" 1LjƔÅ΃0 2.2.1 ̩ żʬ˟ ʡƹ̀ȷŷͨûď 2.13 ˨W 52 - Į 2 ī ē@©ė v 2.12`¡±YĜƩƨ v 2.13±Yķ®Ʃ/microposts 2.3. ±Yŵċ - 53 2.3.2. ơN±YA“ĜƜª IJȷͅˎƒ“ƔÅ”ΪêĻŗͅϨ§Šňʬϙźđ Rails ŃʜΪˋϨ§ƑˣÃcʡЈ͟validation°̞ÉàͅϨ§ƔÅʬϙźȣħĻȁ" 140 Ļ˞ŗv Twitter ɂƴHàGcʡϙźЈ͟ đȃȪ̋ΜćƵ IDE ƾŽ app/models/micropost.rbŽ~Eʼɴà 2.10 ʬEʼ 'ĢĉX 2.10ơN±YĜƜªæ‚ 140 ‹ĭ app/models/micropost.rb class Micropost < ActiveRecord::Base validates :content, length: { maximum: 140 } end ΪɛEʼʶΈȱà̞Ƒ˅ˍƴHRđ 6.2 ̩ͩ˺@˽Ј͟IJȷƴHđÔũƔÅʬϷ϶Ν~ΉΣ 140 Ļ ˞ʬŠňŗ̞ʶ—ΪЈ͟ʬ`ʡ/IJď 2.14 ƺˁRails RɷȻϖͫjƣǫˁƔÅʬŠňĩϙ/ 7.3.3 ̩Rͩ˺@˽ϖͫjƣ v 2.14`¡±Y„ŴàãĥĜƚŪćµ 2.3.3.  ė¸Ãç‚IJ±Y Rails ȣƆħʬ°̞' ȘàGđéʬȁǟɏė'Ϟż˘ƒ̘associationŌȪdʬʡƹɏė̖ ͏ɞʡƹàGǔȤĥ˦ƔÅƴHàGȠȇʡƹɏėÏ͆Eʼɴà 2.11ûƔÅɏėÏ͆Eʼɴà 2.12ʬEʼŃʜΪˋƒ̘ 'ĢĉX 2.11 ė¸Ãç‚IJ±Y app/models/user.rb 54 - Į 2 ī ē@©ė class User < ActiveRecord::Base has_many :microposts end 'ĢĉX 2.12IJ±Yœ ė¸ app/models/micropost.rb class Micropost < ActiveRecord::Base belongs_to :user validates :content, length: { maximum: 140 } end ƴHàGLjΪˋƒ̘ʡď 2.15 ʬďȾ̿ˁ—ȱĊ" microposts ̿Ȥ user_id Ϊ ƺG Railsι Σ Active Record̞LjƔÅûçʡƹƒ̘Έȱ v 2.15±Yoė¸ƞĜ>ŋ đ˟ 11 ˜û˟ 12 ˜ƴHRcʡƔÅûʡƹ'Ϟʬƒ̘șˁ ʡƹʬƺȤƔÅΩRʠƳ û Twitter ˨WʬƔŝ̿ʜđƴHàGđǧ§áconsoleɉȼʡƹƔÅ'Ϟʬƒ̘ǧ§áȘû Rails ŷ ʡ96ƑȤʡʬţ†đúF̼ǀ̼ rails console úFó³ǧ§áʈëΝ~ User.firstBȁǟŶ ͯÕ˟ ʡƹŲLjƒ¦ʬȁǟ΃ó first_user ×ώ 10 $ rails console >> first_user = User.first => # >> first_user.microposts => [#, #] >> micropost = first_user.microposts.first # Micropost.first would also work. => # >> micropost.user => # >> exit ƴđΪɛEʼʬȣë ̼±/ exitõ͡aIJ]γ—˼˝đħĥȁ˭̃*àGǚ Ctrl-D ϗ11 ƴHc ʡ first_user.microposts ̰ÕΪʡƹÔũʬƔÅActive Record R̢³Ψĉ user_id û first_user ʬ ID1ʴéʬƺȤƔÅđ˟ 11 ˜û˟ 12 ˜ƴHRȠɱ~ĒĽ+ƒ̘ʬΪˋʡɧ 10. aʬǧ§áà̞Rșˁ˨W 2.1.1 :001 > ʬǫˁ˞Xˁdcʡ >> EȢĊ"éʬ Ruby ʏȪșˁʬǫˁ˞é 11. û“Ctrl-C” ɂ̺ʈŃϥǚʬȘ“Ctrl-d”X+ƫŽƳ“Ctrl-D” 2.3. ±Yŵċ - 55 2.3.4. ł¾1ĵ Ǧȱˣͅ@˽ Rails ǧ§ćûɏėʬ˨ϱƳ IJȷaȤ϶ìŌͶ̋ːObject-oriented Programmingˣ ˎ OOPʬ˾Ј̞ȠıĒʞ͍Ϊ8ŠňIJȷaȨǦ͎Σ OOP ʬͦàGΑΣΪ ̩ ̦ȱͭIJȷ aʊƦ˨ʬɍƙ4.4 ̩R@˽ƴż͖aGëŒĉΣīȱͯΪ ̩ ƴH{@˽ɏėʬ̄dž̀ȴŌɟ Eʼɴà 2.13 ûEʼɴà 2.14 àGʶ—User û Micropost χι Σ < ˞ǟdž̢ ActiveRecord::BaseΪȘ Active Record "ɏėǫeʬě˨ď 2.16 —/Ϊˋ̄džƒ ˭ιΣ̄dž ActiveRecord::BaseɏėŌͶƼ̞ȁǟŶι͗Ƽ̞LjȁǟŶʬʶs Ruby ʬşƟ ˠˠ 'ĢĉX 2.13User ijĜł¾ app/models/user.rb class User < ActiveRecord::Base . . . end 'ĢĉX 2.14Mcropost ijĜł¾ app/models/micropost.rb class Micropost < ActiveRecord::Base . . . end v 2.16ė¸û{o±Yû{Ĝł¾1ĵ ǧ§ćʬ̄dž̀ȴˑƔģȭ 8ŌɟEʼɴà 2.15 ûEʼɴà 2.16àGʶ—UsersController û Microposts Controller χ̄dž̢ ApplicationControllerIJEʼɴà 2.17 ƺˁApplicationController ̄dž ̢ ActionController::BaseActionController::Base Ș Rails  Action Pack Ŷ"ǧ§ćǫeʬě˨Ϊ8˨ 'Ϟʬƒ˭IJď 2.17 ƺˁ 'ĢĉX 2.15UsersController ijĜł¾ app/controllers/users_controller.rb 56 - Į 2 ī ē@©ė class UsersController < ApplicationController . . . end 'ĢĉX 2.16MicropostsController ijĜł¾ app/controllers/microposts_controller.rb class MicropostsController < ApplicationController . . . end 'ĢĉX 2.17ApplicationController ijĜł¾ app/controllers/application_controller.rb class ApplicationController < ActionController::Base . . . end v 2.17UsersController o MicropostsController Ĝł¾1ĵ ûɏėʬ̄dž˨WιΣ̄dž ActionController::BaseUsersController û MicropostsController ̰ƒ/Ƒ ĥ°̞dIJġʞɏėŌͶʬ̞¯ΣɻΝ~ʬ HTTP ͮɤGÑLj͉ďɷȻƳ HTMLRails ŷʡʬƺ Ȥǧ§ćχ̄dž ApplicationControllerƺG…ł&ʬ͈žR̢³Φʡ4ŷʡʬʬɞ³`dIJ8.4 ̩R@˽IJ]đ ApplicationController Ƃ~Λ´Ȉɧ"ȂŷʡʬƺȤǧ§ćχ±ʩƉûγ—°̞ 2.3.5. ƑňƆ ē@©ė ŁƳƔÅ΂ɸ'ëȘȒmLjEʼǨδ¦ Bitbucket ʬCŶ/ $ git status $ git add -A 2.3. ±Yŵċ - 57 $ git commit -m "Finish toy app" $ git push ιŭƧ‘aŷͨ˾ŭs 8Ƒőʬǫ9ΣŌ4Ȫ˜ȱͭȣës ɐħǫ9*Ȍĵ ʈëa*àGǚʉ 1.5 ̩@˽ʬȈɧLjΪŷʡφ̑¦ Heroku $ git push heroku ǀ̼ΪúFʬªǫȘaŨ˾ǚʉ 2.1 ̩ʬͭȔ ż/ Heroku ŷʡïžŷͨ{ǀ̼ hreoku createʈëŒǀ̼ git push heroku master ʈëῼǀ̼϶ʬúFΡˏʠ:ʛĝʬȁǟŶΪɂŷʡƼ̞cʡȁǟŶ $ heroku run rake db:migrate ΪúFRǚʉʡƹûƔÅʬȁǟɏėȠȇ Heroku ʬȁǟŶΡˏȁǟŶ'ëŗàGđʠ:ʛĝcʡ Ϊŷʡ/IJď 2.18 ƺˁ̖Ϊŷʡcʡ PostgreSQL ȁǟŶ v 2.18ƃŘwĖĔ~Ĝē@©ė 2.4. –Ŀ ̣ɘŌΪ Rails ŷʡʬɍ͊̀ȯ/Ȫ˜ŽÔʬʚ†ŷʡȤPʁ*Ȥ̎ʁ Pʁ • ɍ͊/ Rails 58 - Į 2 ī ē@©ė • @˽/ MVC • ˟ ɐ\Ј/ REST ȹȴ • ŽĶcʡȁǟɏė/ • đʠ:ʛĝΦ̼/ ě4ȁǟŶʬ Web ŷʡ ̎ʁ • ɥ̢ł&ũŚûɂƁ • ɥȤϴƛϷ϶dIJ“ЄϷ”û“ƒ4” • ɥȤʡƹŊʼ • ɥȤʡƹīv • ɥʩƉ°̞ • ŀ • ɥŃʜʡƹûƔÅ'Ϟʬ̢³ƒ̘ • ɥŃʜ“ƒɩ”û“́ƒɩ”°̞ • ɥŃʜƔŝ̿ • ɥ̋ŽȤƮ&ʬɭͤ • ɥȤʷɗʞ͍ƺsʬ2Ƨ Ȫ,ë̆ʬŠňż˘đΪ8Pʁ'̖RǹĄ̎ʁ 2.4.1. ُêīM! • cʡ̡ƻȹ̢³ʠƳɏėʬEʼʈëιΣ Web ʤ϶ûŷʡ96 • ̡ƻȹȤ¤4ƘκƻXʠƳʬEʼȕʞ͍ • Rails cʡ“ɏė-͉ď-ǧ§ć”MVCɏƁ˹˻ Web ŷʡ • nʢ Rails ƴHƒʺ"/ûȁǟɏė96REST ȹȴ§ł/ įȾ’ʬ URL ûǧ§ć³` • Rails ǷǘȁǟЈ͟˳ȯȁǟɏėʬşƟàGcʡ>%o • Rails ŠżǷǘł&ȁǟɏė'Ϟƒ˭ʬ°̞ • àGcʡ Rails ǧ§áđúF̼ Rails ŷʡ96 2.5. ļ 1. Eʼɴà 2.18 "ƔŊňɳ±/ ļđƟЈ͟GɘˀiƔÅ̞"˓Ј͟Ϊ͈žˀŃ̞Ńʜ IJď 2.19 ƺˁʬǽȷ 2. kǹEʼɴà 2.19Lj FILL_IN ǹƳèεʬEʼЈ͟ʡƹɏėʬ name û email şƟχļđď 2.20 'ĢĉX 2.18±YA“ĜŒw´Ưť app/models/micropost.rb 2.5. ļ - 59 class Micropost < ActiveRecord::Base belongs_to :user validates :content, length: { maximum: 140 }, presence: true end 'ĢĉX 2.19wė¸û{P;ŒwƯť app/models/user.rb class User < ActiveRecord::Base has_many :microposts validates FILL_IN, presence: true validates FILL_IN, presence: true end v 2.19±Yû{Œw´ƯťĜ×ð 60 - Į 2 ī ē@©ė v 2.20ė¸û{Œw´ƯťĜ×ð 2.5. ļ - 61 Į 3 ī }êƦ³ĜƩƨ BȪ˜ŽĶƴHͅŽÔ ˴ɼˁŷʡȪ,ë̆ŠňR ʳŽÔΪŷʡȣ˼ŁƳʬŷʡºñʡ ƹƔÅ°̞GÑŁȂʬʩƉûʡƹΓL͒͟˭̃ΣƴH{B ʶW°̞ȤϨʬͦЀ—Ô—— ż ϴƛϷ϶ΪʶWˣÃʬ I2ÊȘ ƑıʬϘʂȳ†Ʈ&ŌΪ¡żʬŷʡ̖͏*ȘƑıʬŽ ˝ ̺ʈ Rails ́͑͝—ȱȘ"/ŽÔě4ȁǟŶʬ³ƛ̏˚Σľ*̞̝Kcʡ˵ HTML żʬϴƛϷ϶ …Ńcʡ Rails żϴƛϷ϶Ȥ ıġ ɳ±Œώ³ƛŠň¿šňȕΪ ˜ŗǿaƜ%sđΪΣ ːƴHR ˗̢³»ɭͤautomated testingʬ϶ʲ̢³»ɭͤàG͔ƴHʴj̢ŧ̋ŽʬEʼȘɗ ˀʬ̖̋Ž ıʬɭͤ˹IΩàG͔ƴHjƕ¿ΌĒύȴEʼkǹŃʜΣːXƋþ°̞ 3.1. I«čĥ©ė û˟ 2 ˜ ɂƴHͅ{ ż ȇ Rails Ϲʲê" sample_appIJEʼɴà 3.1 ƺˁ 1 'ĢĉX 3.1I« Ý©ė $ cd ~/workspace $ rails _4.2.0.beta4_ new sample_app $ cd sample_app/ û 2.1 ̩ ɂIJȷcʡ5˝ IDEàGđé ţ`˓Ϟ żΪŷʡɥƖͅŒȇż ţ`˓ Ϟ ˨W 2.1 ̩ǦȱƴHͅʡȃȪ̋ΜćƾŽŲ̋Μ GemfileŽ~ŷʡƺϳʬ gemEʼɴà 3.2 Eʼɴ à 1.5 ûEʼɴà 2.1 ɂΣ test ˹ʬ gem ȤƺéˑëRsΫ ə̐͝3.7 ̩ɩƮIJȷ ʜđaƬŀ̓ΪŷʡcʡʬƺȤ gemͅŽ~Eʼɴà 11.66 ʬŠň 'ĢĉX 3.2čĥ©ėĜ Gemfile source 'https://rubygems.org' gem 'rails', gem 'sass-rails', gem 'uglifier', gem 'coffee-rails', gem 'jquery-rails', gem 'turbolinks', gem 'jbuilder', '4.2.0.beta4' '5.0.0.beta1' '2.5.3' '4.0.1' '4.0.0.beta2' '2.3.0' '2.2.3' 1. IJȷcʡ5˝ IDEàGcʡ“Goto Anything”úFΝ~φšȃIêŗ̞ȈgĒđȃI˭̃Dž¦ƺϳʬȃIʜđŷ ʡχǻđé ţ`˓ϞÞΝ~ȃIêǽȷà̞ƑʞƬdIJIJȷȼDžê"“Gemfile”ʬȃIR—ʜ̀ȷĊ" ɞŷʡχȤ̞¼ψȼDžȰIʬȃI Gemfile û Gemfile.lockĊɘaàGLjªŷʡ¢ϪȈɧȘ Ϋ~ workspace ȃIĬǀ̼ rm -rf hello_app/ toy_app/ úFÏ͆̿ 1.1Þͅa'ªLjΪŷʡǨδ¦/ Bitbucket GëŒƢģχƑňȕ 63 gem 'rails-html-sanitizer', '1.0.1' gem 'sdoc', '0.4.0', group: :doc group :development, :test do gem 'sqlite3', '1.3.9' gem 'byebug', '3.4.0' gem 'web-console', '2.0.0.beta3' gem 'spring', '1.1.3' end group :test do gem 'minitest-reporters', '1.0.5' gem 'mini_backtrace', '0.1.3' gem 'guard-minitest', '2.3.1' end group :production do gem 'pg', '0.17.1' gem 'rails_12factor', '0.0.2' end ûª˜ ɂƴHͅǀ̼ bundle install úFŀ̓ŲŎ~ Gemfile Ǚłʬ gem̖Ǚł --without production ζϹ2 ŀ̓ʠ:ʛĝcʡʬ gem $ bundle install --without production Φ̼ΪúFëRđŽÔʛĝŀ̓ PostgreSQL ƺϳʬ pg gemđʠ:ʛĝûɭͤʛĝƴHcʡ SQLiteHeroku ȳ¯ż͖đŽÔʛĝûʠ:ʛĝcʡéʬȁǟŶXȘŌΪɼˁŷʡȱͭΪˋȁ ǟŶɥ>%Ŧ¥̖đȪĒŀ̓ψ̐ SQLite ɟ PostgreSQL ňȕƒĥ3 IJȷa'ªŀ̓/Ⱥ gemdIJ Rails ȪΓʬ…DʏȪû Gemfile ǙłʬʏȪäéȣıŒǀ̼ bundle update úFȠȇ gemˀ iŀ̓ʬʏȪûǙłʬ ̤ $ bundle update ȣëƴHῼ¡Ķ» Git CŶ $ git init $ git add -A $ git commit -m "Initialize repository" û˟ ŷʡ ɂƴż͖aȠȇ  README ȃIđŷʡʬɄʲƉȠıʬǪΰΪŷʡƴH{Lj ΪȃIʬɅƁB RDoc ǹ" Markdown $ git mv README.rdoc README.md ʈëŽ~Eʼɴà 3.3 ʬŠň 2. ɩƮΪÏȁŔ Bundler ͘[ɐÞϳΦ̼ bundle install Éà 3. ʜđȒȬΩƳʊXƴż͖aȺ Ĩ łͅĽRIJ]đŽÔʛĝŀ̓ψ̐ PostgreSQLŜȒàGđ͵ɕǮ˯“install configure postgresql ”GÑ“rails postgresql setup”đ5˝ IDE “”Ș Ubuntu 64 - Į 3 ī }êƦ³ĜƩƨ 'ĢĉX 3.36Õčĥ©ėĜ README Û* # Ruby on Rails Tutorial: sample application This is the sample application for the [*Ruby on Rails Tutorial: Learn Web Development with Rails*](http://www.railstutorial.org/) by [Michael Hartl](http://www.michaelhartl.com/). ȣëǫ9Ϊɐǹ³ $ git commit -am "Improve the README" aà̞Ω͘ƒđ 1.4.4 ̩ƴHcʡ git commit -a -m "Message" úFǙł/“φ×»”ʬȋȾ -a ûǫ 9jƣȋȾ -mIJ϶ΪúFƺˁƴHàGLjȋȾèđ Έ×Ƴ git commit -am "Message" ȍʈȪ,ë̆ŠňR ʳcʡΪɼˁŷʡτ%ȣıđ Bitbucket ȇż CŶLjΪŷʡǨδÎ $ git remote add origin git@bitbucket.org:/sample_app.git $ git push -u origin --all # ƮüÌƉƆ ©ė "/ς}Gëν¦ʇīʃЁʬϝЀđΪȑȧϣɛ*àGLjŷʡφ̑¦ Heroku Ïʉ˟ 1 ˜û˟ 2 ˜ ƴż͖cʡEʼɴà 1.8 ûEʼɴà 1.9 ʬEʼ ż șˁ“hello, world!”ʬЄϷʈëǫ9ǹ³Œ Ǩδ¦ Heroku  $ git commit -am "Add hello" $ heroku create $ git push heroku master û 1.5 ̩ ɂaà̞Rʶ¦ 8͐õɯƣʜđȞ˥7.5 ̩R͍Ϫ/ Heroku "ŷʡšψʬ ĒĔ'Ĥʶ¦ʬϷ϶ŷͨûď 1.18 ɂ đϠͯȪ,ʬΣːƴż͖ałȧǨδûφ̑Ϊɂ?̞đάːCŶĢL̖Ω̞ŘȑÔʜđʠ: ʛĝà̞—ʜʬϝЀIJȷν¦û Heroku ȤƒʬϝЀàGȼʶʠ:ʛĝʬȎƗͤʹDž—ϝЀƺđ $ heroku logs ɩƮIJȷałLjʷŃʬŷʡǻ¦ Heroku  łͅǚʉ 7.5 ̩@˽ʬȈɧψ̐ Unicorn 3.2. Ʀ³Ʃƨ ª ̩ʬ’Ģţ`sı'ëƴHàGŽĶŽÔΪɼˁŷʡ/Ȫ̩ƴHͅìŽÔ³ƛϷ϶Τ—˟ ə ż 8 Rails ³`û͉ďXÞºñϴƛ HTMLRails ³`ǻđǧ§ćMVC ʬ CÏ͆ 1.3.3 ̩…ʬ³`Ș"/Ńʜʴƒʬ°̞˟ 2 ˜Ũ˾ˣͅ@˽/ǧ§ć϶ʊƦ REST ȹȴ'ëB˟ 6 ˜ŽĶaRȠɱ~Ēʞ͍ǧ§ćĉƬ  1.3 ̩@˽ʬ Rails ϹʲȃIĬ̀ȴď 1.4RŌƴH ȤƺŬ´Ϊ ̩#ͅđ app/controllers û app/views ȃIĬţ` đ 1.4.4 ̩ƴHͭΣcʡ Git ȒȣıđÃʖʬ#ЀšǷŁƳţ`IJȷacʡ Git sʏȪǧ§ʜđŷͨ ǀ̼ΰúF›Ǟ¦ #ЀšǷʈëŒ żϴƛϷ϶ $ git checkout master $ git checkout -b static-pages 3.2. Ʀ³Ʃƨ - 65 ˟ úFʬ`ʡȘˀiƴHʜđġ4#šǷΪɂƼ̞ě4 master šǷ ż static-pages šǷIJ ȷaƈªŗđ#šǷàGǀ̼ΪúF 3.2.1. Ė¶Ʀ³Ʃƨ ϶ƴHͅcʡ˟ 2 ˜ʡȱʠƳ̡ƻȹʬ generate úFʠƳ ǧ§ćȍʈΪǧ§ćʡȱġʞϴƛϷ ϶τŗLjľúê" StaticPages ðàGʶ—ǧ§ćʬêĻcʡЇŠƁúêɧƴH͑œ ż“ЄϷ” “Ŭ´”Ϸ϶û“ƒ4”Ϸ϶Ōŷʬ³`ꚥ" homehelp û aboutgenerate úFàGǦǸ àζʬÏ ȁ̿Ǚłͅ żʬ³`ƴHͅđúF̼Ǚł“ЄϷ”û“Ŭ´”Ϸ϶ʬ³`XǼƮǙł“ƒ4”Ϸ϶ ʬ³`đ 3.3 ̩Œ@˽Ɯ%ɳ±Ϊ³`ʠƳϴƛϷ϶ǧ§ćʬúFIJEʼɴà 3.4 ƺˁ 'ĢĉX 3.4Ė¶Ʀ³ƩƨËNr $ rails generate controller StaticPages home help create app/controllers/static_pages_controller.rb route get 'static_pages/help' route get 'static_pages/home' invoke erb create app/views/static_pages create app/views/static_pages/home.html.erb create app/views/static_pages/help.html.erb invoke test_unit create test/controllers/static_pages_controller_test.rb invoke helper create app/helpers/static_pages_helper.rb invoke test_unit create test/helpers/static_pages_helper_test.rb invoke assets invoke coffee create app/assets/javascripts/static_pages.js.coffee invoke scss create app/assets/stylesheets/static_pages.css.scss Ϻgͭ rails generate àGˣŽƳ rails gϪɘ'ĤRails Ωǫe/•úFʬˣŽƊƁÏ͆̿ 3.1"/̿ΰȔˀȪ,R ʳcʡúFʬŁȂƊƁXđŃϥcʡħĥȁ Rails ŽÔ̕ƵĥƵŒχR cʡˣŽƊƁ ř 3.1Rails n(ĜİC°­ Ú°­ İC°­ $ rails server $ rails s $ rails console $ rails c $ rails generate $ rails g $ bundle install $ bundle $ rake test $ rake đ̄̆'ªIJȷacʡ GitȣıLjϴƛϷ϶ǧ§ćŌŷʬȃIǨδ¦άːCŶ 66 - Į 3 ī }êƦ³ĜƩƨ $ git status $ git add -A $ git commit -m "Add a Static Pages controller" $ git push -u origin static-pages ȣë úFʬƮƞȘLj static-pages #ЀšǷǨδ¦ BitbucketGëŒǨδȒàGʵʦë϶ʬÏȁ ˣŽƳ $ git push đʜŃʬŽÔΣːƴ ̦χR{ǫ9ŒǨδXȘ"/̼ȃˣɪBΪƍëƴHRʵʦǫ9Ϊ ə ɩƮđEʼɴà 3.4 ƴHS~ʬǧ§ćêcʡЇŠƁ żʬǧ§ćȃIêcʡ̻ŸƁƺGS~ “StaticPages”ƒ¦ʬȃIȘ static_pages_controller.rbΪÞȘ ˋ˳ł…ŃđúF̼*àGcʡ̻Ÿ Ɓ $ rails generate controller static_pages ... ΪúF*RʠƳê" static_pages_controller.rb ʬǧ§ćȃIĊ" Ruby ʬ˨êcʡЇŠƁ4.4 ̩ƺGǫ¦ǧ§ćȒƴRcʡЇŠƁΣΪȘƴʬ=ζǕĊ" Ruby ȃIê ̦cʡ̻ŸƁ ƺG Rails ʠƳćcʡ underscore ȈɧLjЇŠƁΕǞƳ̻ŸƁ Ϻgͭ IJȷđʠƳEʼȒ—ʜ/ϖͫʺοIJ]dzϕǵ`ŗƑȤʡ/Ȋɩ 3.1 @˽/ 8IJ]đ Rails dzϕǵ`ʬȈɧ ߥ 3.1ÒƙÓ2 ÉcŒőƕđŽÔ Rails ŷʡʬΣː*à̞Rʓϖųı Rails ǫe/ 8ţ†̞ĦŬ´ƴHΩÍǵ ` $dȱͭ ŭ͆ʬƧ‘ȘȠǹǧ§ćʬêĻΪȒaƒ¢ϪʠƳʬȃIʠƳǧ§ćȒϪ/ǧ §ćȃIȪΓ'ĤRails ΩRʠƳƑĥ…DȃIÏ͆Eʼɴà 3.4dzϕʠƳʬȃI??ͅ¢Ϫ ǧ§ćȃIῼ¢Ϫ 8Λ´ʬȃIđ 2.2 ̩û 2.3 ̩ƴHʶ¦rails generate úFΩR̢³k ǹ routes.rb ȃIĊɘƴH*Ƭ̢³dzϕΪ8kǹđ Rails ƴHàGcʡ rails destroy úF ŁƳdzϕǵ` ̦ȱͭ϶ΪúFȘʴ6Ǎɯʬ $ rails generate controller StaticPages home help $ rails destroy controller StaticPages home help ˟ 6 ˜Rcʡ϶ʬúFʠƳɏė $ rails generate model User name:string email:string Ϊǵ`àGcʡ϶ʬúFdzϕ $ rails destroy model User đΪdĺƴHàGʵʦúF̼…^ʬÏȁͯ¦˟ 6 ˜Ȓʶʶa̞ïÔʜ">%àGΪ% s ŌɏėȱͭΩɰѦdzϕΡˏ˟ 2 ˜Ũ˾ˣͅ@˽/Ρˏ˟ 6 ˜ŽĶRɱ~@˽ΡˏιΣ϶ ʬúFǹ×ȁǟŶʬʔƛ 3.2. Ʀ³Ʃƨ - 67 $ bundle exec rake db:migrate ƴHàGcʡ϶ʬúFdzϕª Ρˏǵ` $ bundle exec rake db:rollback IJȷͅĉ¦ȣŽĶʬʔƛàGcʡ $ bundle exec rake db:migrate VERSION=0 aà̞ʘ¦/LjȁĻ 0 ǞƳ…DʬȁĻŗRĉ¦ʴŷʬʏȪΪ8ʏȪȁĻȘǚʉΡˏǀ̼ʬϺŵǤ ʬ ʺοΪ8LJȫƴHŗàGƒƕŷŌŽÔΣːν¦ʬçˋϝЀ/ Eʼɴà 3.4 ʠƳϴƛϷ϶ǧ§ćʬúFR̢³kǹΐʢȃIconfig/routes.rbƴHđ 1.3.4 ̩Ũ˾ ˣʦ@˽ΣΐʢȃIľʬ`ʡȘŃʜ URL û̏Ϸ'ϞʬŌŷƒ˭ď 2.11ΐʢȃIđ config ȃIĬ Rails đΪȃIĬļǻŷʡʬψ̐ȃIď 3.1 v 3.1čĥ©ė config Û*…ĜA“ Ċ"ʠƳǧ§ćȒƴHǙł/ home û help ³`ƺGđΐʢȃIŨ˾ɳ±/ʴŷʬ͈žIJEʼɴà 3.5 ƺˁ 'ĢĉX 3.5Ʀ³ƩƨËNr home o help R2ĜŹĘ config/routes.rb Rails.application.routes.draw do get 'static_pages/home' get 'static_pages/help' . 68 - Į 3 ī }êƦ³ĜƩƨ . . end IJʬ͈ž get 'static_pages/home' LjỐ /static_pages/home ʬͮɤȗŏ¦ϴƛϷ϶ǧ§ćʬ home ³`ÝĤget ̿ȔΪΐʢþŷ GET ͮɤGET Ș HTTPΉȃȪSΝÂ͖Hypertext Transfer ProtocolǷǘʬěȪͮɤȈɧ' Ȋɩ 3.2đΪdĺƈƴHđϴƛϷ϶ǧ§ćʠƳ home ³`Ȓŗ̢³đ /static_pages/home ĒḚ̆ ƒ/ Ϸ϶̫ƬȼʶΪϷ϶ǚʉ 1.3.2 ̩ʬȈɧó³ Rails ŽÔȥ²ć $ rails server -b $IP -p $PORT # ˆðwŐ ĜęŎdƥ¼Ř `rails server` ʈë͞ϝ /static_pages/homeIJď 3.2 ƺˁ v 3.2İƟĜƮƩ/static_pages/home ߥ3.2GET į ΉȃȪSΝÂ͖HTTPł&/•ěȪǵ`GETPOSTPATCH û DELETEΪĈ³̿͢ˁŅƹ˝ ʣ̠ιŭŀ̓/ ˋɮ͊ćdIJ ChromeFirefox Ƶ Safariûȥ²ćιŭRΦ̼  Web ȥ² ćdIJ Apache Ƶ Nginx'Ϟʬǵ`Ȥ ʁƑύͅaͅʺοđȪĒʣ̠ŽÔ Rails ŷʡ ȒŅƹ˝ûȥ²ćđé áʑʞ͝ĢXȘ3̕ȘéʬɍƙÖ REST ȹȴƋþʬ Web Ɇȹ 3.2. Ʀ³Ʃƨ - 69 ºǖ RailsχƑύ͉Ō HTTP ³͢ʬŃʜƴHđ˟ 2 ˜Ũ˾ˣͅ@˽/ RESTB˟ 7 ˜ŽĶRs Ƞͩ˺ʬ@˽ GET Șȣŭʡʬ HTTP ǵ`ʡȱͯÕ̏̂ʬȁǟľʬƮƞȘ“ͯÕ ̏Ϸ”ƈa͞ϝ http://www.google.com Ƶ http://www.wikipedia.org Ȓɮ͊ćÔδʬŗȘ GET ͮɤPOST Ș˟3ˋȣŭ ʡʬǵ`ƈaǫ9̿ÃȒɮ͊ćÔδʬŗȘ POST ͮɤđ Rails ŷʡPOST ͮɤ ̦ʡȱ żȺ ̈́Σ HTTP *x͛ POST ǀ̼Ƞȇǵ`dIJǫ9ɩ‹̿ÃȒÔδʬ POST ͮɤRđ̏˚ ż ȇʡƹÝĤ³͢PATCH û DELETEš¥ʡȱȠȇûϕɜȥ²ćʬȺ̈́Ϊǵ `ɥ GET û POST τ%ŭʡĊ"ɮ͊ćɥȤŠżŌΪˋͮɤʬǷǘΣȤ8 Web Ɇȹºǖ RailsιΣ 8̙ȔʬġʞȈƁ͔ľʶΈȱŗvȘɮ͊ćԗʬ ɂƺGΪĈˋͮɤ˨ė Rails χǷǘ ͅƬƀȔʪΪϷ϶ȘƜ%ȱʬƴH{đȃȪ̋Μćʶ ϴƛϷ϶ǧ§ćȃIaŷͨRʶ¦˨WE ʼɴà 3.6 ƺˁʬŠňaà̞ɩƮ¦/v˟ 2 ˜ʬʡƹûƔÅǧ§ćϴƛϷ϶ǧ§ćɥcʡȾ’ ʬ REST ³`ΪŌϴƛϷ϶ȱͭȘƑŭ͆ʬɠ˛ REST ȹȴ̞͍ƺȤϝЀ 'ĢĉX 3.6'ĢĉX 3.4 Ė¶ĜƦ³ƩƨËNr app/controllers/static_pages_controller.rb class StaticPagesController < ApplicationController def home end def help end end B϶Eʼʬ class àGʶ—static_pages_controller.rb ȃIł&/ ˨ê" StaticPagesController˨Ș ˋ˹˻™ȁ*ßȈɧʬȤǽȈƁdIJ home û help ³`ŗȘȈɧcʡ def ƒϗĻł &2.3.4 ̩ͭΣŔǖä < ̿ˁ StaticPagesController ̄dž̢ ApplicationController ˨ΪŗƮøʹƴH ł&ʬϷ϶ǔȤ/ Rails ǫeʬħώ°̞ƴHRđ 4.4 ̩Ƞͩ˺ʬ@˽˨û̄dž đȪdϴƛϷ϶ǧ§ćʬȈɧЎ͒χȘ˓ʬ def home end def help end IJȷȘȚιʬ Ruby EʼΪȈɧ>%*s/Σđ Rails ŗ ɂ/StaticPagesController Ș  Ruby ˨XȘĊ"ľ̄dž̢ ApplicationController…ʬȈɧŌ Rails ȱͭŗȤ/ʒɚƮ& ͞ϝ /static_pages/home ȒRails RđϴƛϷ϶ǧ§ćōDž home ³`ʈëǀ̼ͨ³`ŒɷȻʴŷʬ͉ď MVC ʬ VÏ͆ 1.3.3 ̩đȪdhome ³`Ș˓ʬƺG͞ϝ /static_pages/home ëÞRɷȻ͉ ďτ%͉ďȘ>%ɂĺƜ%Ƽ̞Dž¦ľ÷ IJȷaŒʶ Eʼɴà 3.4 ʬΝ—Ƶ̞͛ʘ¦³`û͉ď'ϞʬŌŷƒ˭ home ³`Ōŷʬ͉ďȘ home.html.erb3.4 ̩Rõ͡a .erb Ș>%Ʈƞʶ¦ .html aƵ͛ŗĭƠ/ΪȃIěȪŗȘ HTMLIJEʼɴà 3.7 ƺˁ 70 - Į 3 ī }êƦ³ĜƩƨ 'ĢĉX 3.7“ƮƩ”Ė¶Ĝŝv app/views/static_pages/home.html.erb

    StaticPages#home

    Find me in app/views/static_pages/home.html.erb

    help ³`ʬ͉ď˨WIJEʼɴÃ 3.8 ƺˁ 'ĢĉX 3.8“£S”ƩƨĖ¶Ĝŝv app/views/static_pages/help.html.erb

    StaticPages#help

    Find me in app/views/static_pages/help.html.erb

    Ϊ͉ďχÞȘÆYʡʬľHʬŠňχȤ  ˴ȾЀh1 Ⱦˢû șˁ͉ďȃIŁȂΐƏʬɛ ̳p Ⱦˢ 3.2.2. 6ÕƦ³ƩƨĜA“ ƴHRđ 3.4 ̩ɳ± 8ˣÃʬ³ƛŠňʜđΪ8ϴƛŠňʬļđȘ"/Ɔͱ IƑύͅʬ2 Rails ʬ ͉ďàGÞºñϴƛʬ HTMLƺGƴHʟ̣Ȍϳ/͍ Rails ŗàGkǹ“ЄϷ”û“Ŭ´”Ϸ϶ʬŠňIJEʼ ɴà 3.9 û 3.10 ƺˁ 'ĢĉX 3.96Õ“ƮƩ”Ĝ HTML app/views/static_pages/home.html.erb

    Sample App

    This is the home page for the Ruby on Rails Tutorial sample application.

    'ĢĉX 3.106Õ“£S”ƩƨĜ HTML app/views/static_pages/help.html.erb

    Help

    Get help on the Ruby on Rails Tutorial at the Rails Tutorial help section. To get help on this sample app, see the Ruby on Rails Tutorial book.

    kǹ'ëΪϷ϶șˁʬŠňIJď 3.3 û 3.4 ƺˁ 3.2. Ʀ³Ʃƨ - 71 v 3.36ÕkĜ“ƮƩ” 72 - Į 3 ī }êƦ³ĜƩƨ v 3.46ÕkĜ“£S”Ʃƨ 3.3. ¬‰ąŨ ƴH żŲkǹ/“ЄϷ”û“Ŭ´”Ϸ϶ʬŠň϶ͅɳ±“ƒ4”Ϸ϶sΪɂʬǹ³Ȓȣı̋Ž̢³» ɭͤˀ͒ŃʜʬȈɧɗˀŌȪ,ŽÔʬŷʡȱͭƴH̋Žʬɭͤ˹IȤ`ʡ … Ș ˋŀϢ NJǩȉ …3`"ɸʼʬȃɈ̺ʈ̋ͅŽЁĤʬEʼXȘIJȷȈɧƒƈɭ̞ͤ´ƴHƘκŽÔ Ċ"Ȥ/ɭͤȼDžϝЀƺʡʬȒϞR׌ΣƴHͅĄ4̋ŽɭͤƼ̼ƺGͅŘȑŽĶ˸+ •(ɞ Rails ŽÔ̕χ͒éɭͤȘı+ƫX†\ʬ`ɧĥˋĥɂȣΧȤ ēϏŌ“ɭͤІ³ŽÔ”TestDriven Developmentˣˎ TDDʬΞ͜4 ¿šʆϟTDD Ș ˋɭͤLJȫːŵöͅ{̋ŽĪͻʬɭ ͤʈëŒ̋ŽŷʡʬEʼ͔ɭͤιΣȪ,ϊʡ ˋΘώ˴˞èʳ͋ʬɭͤȈɇÞđεƈʬȒmƼ cʡ TDD̖ɅρĿ TDD ʞƙȊɩ 3.3 ߥ 3.3!à7ąŨ £Ȇ]ȒGÑIJ]ɭͤ'ªȣıƀȔʪ">%ͅɭͤđƴʶȱ̋Ž̢³»ɭͤ#ͅȤıġ 1. ɭ̞ͤς}“ĉƇ”regressionÉʢ4Ⱥ8ÍĊ'ª̞ʡʬ°̞̞ʡ/ 2. Ȥɭͤύȴǹ×ŃʜȈƁX°̞×ȒȠȤ̢j 3. ɭͤȘŷʡEʼʬŅƹĊɘàG´ƴH͑͝GѐłIJ]˭̃ʬ…D˹I96 Gıġχͅɤ{̋ŽɭͤXđƑĥƧ‘TDD AȤľʬJo]ȒGÑIJ]ɭͤφšÕ 4a̋Žɭͤʬʊ˸ːźƑĥŽÔ̕Ôʜʊ˸'ëDHȠpì4{̋ŽɭͤϪɘ'ĤΩÕ 4ɭͤΚ'ŷʡEʼȤĥϯaŌƬŃʜʬ°̞Ȥĥɱʬ͒͠GÑȨȱđ>%Ƨ‘Ϊ°̞Rπ ¦ʽĕ ʜđȣıȤ 8ǙŎȈϏõ͡ƴH>%Ȓmŷͨ{ŽɭͤGÑ>%ȒmŁʡɭͤɄǟƴ ̢ŧʬ˾Ј́— 8ż͖ • ûŷʡEʼʴɟIJȷɭͤEʼʒ¥ˣʻpì4{̋Žɭͤ • IJȷŌƬŃʜʬ°̞Șʒ¥ɴɌpì4{̋ŽŷʡEʼʈëŒ̋ŽɭͤǹΫŃʜʬȈ Ɓ • ŀȘīˠħ2iϫΈ͆ͅ"ŀʴƒʬ°̞{̋Žɭͤ • ÞͅÔʜ ϝЀŗ̋Ž ɭͤύʜΪˋϝЀGς}ĉƇʈëŒ̋ŽŷʡEʼkɗϝ Ѐ • Řώ"Gëà̞kǹʬEʼdIJ HTML ̀ȴʬ˺̩̋Žɭͤ • ύȴ'ª̋ͅŽɭͤϱɭͤňȕ—ϖʬEʼ đŃϥʬŽÔɄǟΰȈϏƴH ̦{̋Žǧ§ćûɏėɭͤʈëŒ̋ŽϱƳɭͤɭͤɏ ė͉ďûǧ§ć̀èđ ΈȒʬ̿ʜIJȷŷʡEʼƑňȕ—ϖƵ̕˾ŭR׳͉ďŗȘΪ ɂƴHŗŁɭͤ 4. ͩƧÏ͆ Rails Ķ= David Heinemeier Hansson Žʬ ˦ȃ˜ TDD is dead. Long live testing 3.3. ¬‰ąŨ - 73 ƴH#̋ͅŽʬɭͤ˨ėȘǧ§ćɭͤȪ̩ŽĶ̋Žɏėɭͤ˟ 6 ˜ŽĶ̋ŽûϱƳɭͤ˟ 7 ˜ŽĶ̋ŽϱƳɭͤʬ`ʡʒ¥ħľ̞ɏǓʡƹđɮ͊ćûŷʡ96ʬΣːȣ˼RƳ"ƴHʬ# ͅƒɩŌͶΣǧ§ćɭͤȠňȕƻ 3.3.1. Į ąŨ ʜđƴHͅđΪŷʡɳ± “ƒ4”Ϸ϶ƴHRʶ¦ΪɭͤƑˣʻƺGǚʉȊɩ 3.3ʬǙŎȈ ϏƴHͅ{̋ŽɭͤʈëcʡĪͻʬɭͤІ³ƴH̋ŽŷʡEʼ ʹƻɭͤȘI†ȤǛƶʬ2ƧͅɤŌ Rails û Ruby χȤɱ~ʬ/͍Ϊ%ȑŗ̋Žɭͤà̞Ȥʁwí= ΣRails Ũ˾"ƴH͍/ȣϯʬφšĊ"ǀ̼ rails generate controller úFȒEʼɴà 3.4̢ ³ʠƳ/ ɭͤȃIƴHàGBΪȃI~ƻ $ ls test/controllers/ static_pages_controller_test.rb ƴHʶ ΪȃIʬŠňIJEʼɴà 3.11 ƺˁ 'ĢĉX 3.11Ʀ³ƩƨËNrĖ¶ĜąŨ GREEN test/controllers/static_pages_controller_test.rb require 'test_helper' class StaticPagesControllerTest < ActionController::TestCase test "should get home" do get :home assert_response :success end test "should get help" do get :help assert_response :success end end ʜđȌϳʞ͍ͩ˺ʬÜɧΣàGʶ—…ȤɭͤŌŷƴHđúF̼S~ʬ³`Eʼɴ à 3.4đɞɭͤ{͞ϝ³`ʈëˀ͒ιΣ“Ȇ͏”ƒ¦ɗˀʬþŷ…get ̿ˁɭͤȧȦ ΪϷ϶ȘȚιʬ̏ϷàGιΣ GET ͮɤ͞ϝȊɩ 3.2 :success þŷȘŌ HTTP þŷʼʬǎͶ̿ˁ đΪό̿ˁ 200 OK*ŗȘͭ϶Ϊɭͤ test "should get home" do get :home assert_response :success end ľʬƮƞȘ ƴHͅɭͤЄϷτ%ŗì home ³`ÔΈ  GET ͮɤˀ͒ƒ¦ʬȘ̿ˁƳ°ʬþŷʼ ϶ƴHͅΦ̼ɭͤ˹Iˀ͒ɭͤʜđàGιΣȈɧȘǚʉ϶ʬȈƁΦ̼ rake K²Ȋɩ 2.1 5 5. 2.2 ̩ͭΣđȤ8˭̃ϳͅcʡ bundle exec…ŗºǖ5˝ IDEΣ"/̿ΰŁȂƴ±/ ̦Ƨ‘ƴ χRʵʦ bundle execIJȷν¦ϖͫŒ±ͤͤ 74 - Į 3 ī }êƦ³ĜƩƨ 'ĢĉX 3.12GREEN $ bundle exec rake test 2 tests, 2 assertions, 0 failures, 0 errors, 0 skips ǚʉϳɤ ŽĶɭͤ˹IàGιΣGREENIJȷɥǚʉ 3.7.1 ̩ʬͭȔɳ± MiniTest Njõːŵ Rʶ¦̨̉Ϻgͭ ɭ̪ͤͅʁȒϞó³Ċ"1ͅó³ Spring ȥ²ćϽ±Ιφš Rails ʛĝ ΣΪ əÞđЄɐó³Ȓǀ̼ 2ó³ Ruby *̪ͅʁwȒϞ˟3ʁàGcʡ 3.7.3 ̩Ǩ̯ʬ Guard ǹĄ 3.3.2. Əĸ ƴHđȊɩ 3.3ͭΣTDD ɬːȘ{̋Ž Īͻɭͤʈë̋ŽŷʡEʼ͔ɭͤιΣȣëŒǚϳύ ȴEʼĊ"Ƒĥɭͤţ†χcʡ˲̨̿ˁĪͻʬɭͤcʡ̨̉̿ˁιΣʬɭͤƺGΪɬːȤȒ*ß “ν˲-×̉-ύȴ”ƓʛΪ ̩ƴH{ŁƳΪƓʛʬ˟ ə̋Ž Īͻɭͤ“ν˲”ʈëđ 3.3.3 ̩ ×̉3.4.3 ̩ύȴ6 Є{ƴHͅ"“ƒ4”Ϸ϶̋Ž ĪͻɭͤÏʉEʼɴà 3.11aƵ̞͛ʘ¦ŷͨƜ%ŽIJEʼɴà 3.13 ƺˁ 'ĢĉX 3.13“>”ƩƨĜąŨ RED test/controllers/static_pages_controller_test.rb require 'test_helper' class StaticPagesControllerTest < ActionController::TestCase test "should get home" do get :home assert_response :success end test "should get help" do get :help assert_response :success end test "should get about" do get :about assert_response :success end end IJЌ<șˁʬτ•̼ƺˁ"“ƒ4”Ϸ϶̋ŽʬɭͤЄϷû“Ŭ´”Ϸ϶ʬɭͤ ɂÞΣLj“home”Ƶ “help”ǞƳ/“about” ΪɭͤʜđĪͻ 6. Ў͒Ƨ‘ǀ̼ rake test K²ëIJȷɭͤĪͻRșˁ˲̨XɭͤιΣRșˁ̨̫̉Ƭșˁ̨̉Ïʉ 3.7.1 ̩ ʬͭȔ 3.3. ¬‰ąŨ - 75 'ĢĉX 3.14RED $ bundle exec rake test 3 tests, 2 assertions, 0 failures, 1 errors, 0 skips 3.3.3. bŃ ʜđȤ/ ĪͻɭͤREDƴHͅđΪĪͻɭͤʬϖͫɯƣǙˁ͔ɭͤιΣGREEN*ŗ ȘͅŃʜ àG͞ϝʬ“ƒ4”Ϸ϶ ƴH{ʶ ΪĪͻɭͤ́—ʬϖͫɯƣ 7 'ĢĉX 3.15RED $ bundle exec rake test ActionController::UrlGenerationError: No route matches {:action=>"about", :controller=>"static_pages"} ΪϖͫɯƣͭɥȤDž¦ϳͅʬ³`ûǧ§ć˹è…ŃŗȘǫˁƴHͅđΐʢȃIɳ± ͈žÏ ʉEʼɴà 3.5ƴHàG̋ŽIJEʼɴà 3.16 ƺˁʬΐʢ 'ĢĉX 3.16ĈP about ŹĘ RED config/routes.rb Rails.application.routes.draw do get 'static_pages/home' get 'static_pages/help' get 'static_pages/about' . . . end ΪɛEʼЌ<șˁʬτ̼õ͡ RailsLjỐ /static_pages/about Ϸ϶ʬ GET ͮɤ9́ϴƛϷ϶ǧ§ćʬ about ³`ġʞ ʈëŒΦ̼ɭͤ˹IAʈȌɧιΣΣϖͫɯƣ×/ 'ĢĉX 3.17RED $ bundle exec rake test AbstractController::ActionNotFound: The action 'about' could not be found for StaticPagesController ΪϖͫɯƣʬƮƞȘϴƛϷ϶ǧ§ć̎Œ about ³`ƴHàGÏʉEʼɴà 3.6 ̋ŽΪ³`IJ Eʼɴà 3.18 ƺˁ 'ĢĉX 3.18wƦ³ƩƨËNrĈP about R2 RED app/controllers/static_pages_controller.rb 7. đȤ8˭̃à̞ͅǑ³ɺ³ȰΑΣɸʼʬϖͫΐƏ——“ͱʡΎΒ”3.7.2 ̩@˽/IJ]ΣɻͱʡΎΒς}șˁϳͅ ʬŠň 76 - Į 3 ī }êƦ³ĜƩƨ class StaticPagesController < ApplicationController def home end def help end def about end end ʜđɭͤfȏĪͻΣɭͤɯƣÐ×/ $ bundle exec rake test ActionView::MissingTemplate: Missing template static_pages/about Ϊ̿ˁɥȤɏȲđ Rails ɏȲŗȘ͉ď3.2.1 ̩ͭΣhome ³`Ōŷʬ͉ďȘ home.html.erbiļđ app/views/static_pages ȃIĬƺGƴHͅđΪȃIĬȇż ȃIŲͅúê" about.html.erb đéʬ˭̃ȇżȃIȤéʬȈɧΣħĥȁƧ‘χàGđƬͅȇżȃIʬȃIĬʁ˜АȾã ϗʈëđƅ—ʬ̱ÃζǕ“ȇżȃI”Ƶ̕àGcʡȃȪ̋Μćʬ“ȃI”̱ÃȇżȃIëŒζǕi ļʬY̐Ϫɘ'ĤΩàGcʡƴȣąɑʬ Unix touch úFʡɧIJ $ touch app/views/static_pages/about.html.erb touch ʬ#ͅ`ʡȘȠȇȃIƵȃIĬʬkǹȒϞƸ¥Ȍ…DǽȷXȤ®`ʡIJȷȃIļđŗ Rȇż IJȷcʡ5˝ IDEƵ͛ͅ¨ȇȃIɀÏ͆ 1.3.1 ̩ đɗˀʬȃIĬ ż about.html.erb ȃI'ëͅđ…Ž~Eʼɴà 3.19 ʬŠň 'ĢĉX 3.19“>”ƩƨĜA“ GREEN app/views/static_pages/about.html.erb

    About

    The Ruby on Rails Tutorial is a book and screencast series to teach web development with Ruby on Rails. This is the sample application for the tutorial.

    ʜđΦ̼ rake testRʶ¦ɭͤιΣ/ 'ĢĉX 3.20GREEN $ bundle exec rake test 3 tests, 3 assertions, 0 failures, 0 errors, 0 skips ƈʈƴHΩàGđɮ͊ćȼʶΪϷ϶ď 3.5GϢɭͤɓЉƴH 3.3. ¬‰ąŨ - 77 v 3.5ÝĈPĜ“>”Ʃƨ/static_pages/about 3.3.4. ƕï ʜđɭͤŨ˾×̉/ƴHàG̢jĒŘƧύȴ/ŽÔŷʡȒEʼ˾ŭR“×ø”ƮƞȘEʼR׃ ϦăĆȤħώʬύģʣ̠RđƮXȘ=˨RƺG˾ŭύȴLjEʼ×ˣɪ 8ȘƑύͅʬ2 ƧƴHʬɼˁŷʡʜđΩƑőɥ>%àύȴʬΣEʼȌȒȌ©đ×øƺG 3.4.3 ̩ŗͅŽĶύ ȴ 3.4. çĎR³A“ĜƩƨ ƴHŨ˾" 8ϴƛϷ϶ ż/³`û͉ďʜđͅˑƔɳ± 8³ƛŠňɄǟƺđʬϷ϶é̖×» ƴH͔ͅȾЀɄǟϷ϶ʬŠň×»ǹ×ȾЀ¦Ÿˤˤʷɗ³ƛΩȤ1͖Ϊ%s̞"˟ 7 ˜Ńʜʬʷɗ ³ƛŠňƾěʿ ƴHʬ͑œȘkǹЄϷ“Ŭ´”Ϸ϶û“ƒ4”Ϸ϶͔ɞϷșˁʬȾЀχ ɂ"ɘƴHͅđϷ϶ʬ͉ ďcʡ Ⱦˢħĥȁɮ͊ćχRđɮ͊ć˖ÚʬϸφșˁȾЀʬŠň̖ȾЀŌ“Ǯ˯ƂǶP »”Search-Engine Optimizationˣˎ SEO*ȤıġƴHͅcʡŁȂʬ“ν˲-×̉-ύȴ”Ɠʛ {"Ϸ ϶ʬȾЀ̋Ž 8ˣÃʬɭͤν˲ʈ뚥đϷ϶ɳ±ȾЀ×̉ȣëcʡũŚȃIÎϪ ύģŠňύȴȪ̩̀ȯȒϴƛϷ϶ʬȾЀχR×Ƴ“<Ϸ϶ʬêĻ> | Ruby on Rails Tutorial Sample App”ΪˋƊƁ̿ 3.2 rails new úFR ż ũŚȃIΣʜđȣıʡƴHύúêΪȃI $ mv app/views/layouts/application.html.erb layout_file # àħR 78 - Į 3 ī }êƦ³ĜƩƨ đʷŃʬŷʡaϳͅΪ%sΣɥȤΪȃI̞͔aȠıĒʞ͍ľʬ`ʡ ř 3.2čĥ©ė}ê âƦ³A“ĜƩƨ Ʃƨ URL }êôƭ ЄϷ Ŭ´ ƒ4 /static_pages/home /static_pages/help /static_pages/about "Ruby on Rails Tutorial Sample App" "Ruby on Rails Tutorial Sample App" "Ruby on Rails Tutorial Sample App" bRƑF "Home" "Help" "About" 3.4.1. ąŨôƭƏĸ ɳ±ȾЀ'ªƴHͅĽ+̏Ϸʬ ̦̀ȴIJEʼɴà 3.21 ƺˁ 'ĢĉX 3.21ņƩŒĜ HTML Ŀï <!DOCTYPE html> <html> <head> <title>Greeting

    Hello, world!

    ΪɛEʼʬȣϸφȘ“ȃɈ˨ėĠȔ”document type declarationˣˎ doctypeõ͡ɮ͊ćcʡÿ HTML ʏȪȪdcʡ HTML58 ϬëȘ head φšºñ  title Ⱦˢ…ʬŠňȘ“Greeting”ʈ ëȘ body φšºñ  p Ⱦˢɛ̳…ʬŠňȘ“Hello, world!”Šňʬ̍ΫȘàζʬHTML Rʒ¥ŌƐ˓ʪ§̿˞û˓ɅχŔƚʦX̍ΫàG͔ȃɈ̀ȴȠɴȜ ƴHͅcʡ assert_select Ȉɧš¥"̿ 3.2 ʬɞȾЀ̋ŽˣÃʬɭͤèŲ¦Eʼɴà 3.13 ʬɭͤ assert_select Ȉɧʬ`ʡȘɉȼȤɥȤǙłʬ HTML ȾˢΪˋȈɧȤȒ*ß“ζǕ˞”BȈɧêà Gʶ—Ϊ ʁ9 assert_select "title", "Home | Ruby on Rails Tutorial Sample App" Ϊ̼Eʼʬ`ʡȘɉȼȤɥȤ ȾˢGхʬŠňȘȘĻ˞ “Home | Ruby on Rails Tutorial Sample App”LjΪɂʬEʼš¥ǻ¦Ϸ϶ʬɭͤƒ¦ʬ̀ȷIJEʼɴà 3.22 ƺˁ 'ĢĉX 3.22P;ôƭąŨkĜƦ³ƩƨËNrąŨ RED test/controllers/static_pages_controller_test.rb require 'test_helper' class StaticPagesControllerTest < ActionController::TestCase 8. HTML ʳđ×»șƁĠȔ  doctype àGˀiȨȱɮ͊ćΩàGɗˀ͍ȵϷ϶<!DOCTYPE html> Ϊˋȳ"ˣÃʬ ɅƁȘȣȇʬ HTML Ⱦ’ HTML5 ʬ ʒ̨ 9. Rails ǙÄ@˽ɭͤʬȃ˜—/ŭʡʬ MiniTest Ȇ͏ 3.4. çĎR³A“ĜƩƨ - 79 test "should get home" do get :home assert_response :success assert_select "title", "Home | Ruby on Rails Tutorial Sample App" end test "should get help" do get :help assert_response :success assert_select "title", "Help | Ruby on Rails Tutorial Sample App" end test "should get about" do get :about assert_response :success assert_select "title", "About | Ruby on Rails Tutorial Sample App" end end IJȷa͋ƒđȾЀύģcʡ“Ruby on Rails Tutorial Sample App”ĴàGʶ  3.6 ̩ʬ˸+ Žıɭͤ'ëŷͨˀ͒ ʜđɭͤ˹IȘĪͻʬRED 'ĢĉX 3.23RED $ bundle exec rake test 3 tests, 6 assertions, 3 failures, 0 errors, 0 skips 3.4.2. ĈPƩƨôƭbŃ ʜđƴHͅ"ɞϷ϶ɳ±ȾЀ͔ª ̩ʬɭͤιΣÏʉEʼɴà 3.21 ʬ HTML ̀ȴLjEʼɴ à 3.9 ʬЄϷŠňǞƳEʼɴà 3.24 ʬŠň 'ĢĉX 3.24@çÚ HTML ĿïĜƮƩ RED app/views/static_pages/home.html.erb <!DOCTYPE html> <html> <head> <title>Home | Ruby on Rails Tutorial Sample App

    Sample App

    This is the home page for the Ruby on Rails Tutorial sample application.

    kǹ'ëЄϷIJď 3.6 ƺˁ10 80 - Į 3 ī }êƦ³ĜƩƨ v 3.6ĈPôƭkĜƮƩ ʈëcʡ˨WʬȈƁkǹ“Ŭ´”Ϸ϶û“ƒ4”Ϸ϶ƒ¦ʬEʼIJEʼɴà 3.25 ûEʼɴà 3.26 ƺˁ 'ĢĉX 3.25@çÚ HTML ĿïĜ“£S”Ʃƨ RED app/views/static_pages/help.html.erb Help | Ruby on Rails Tutorial Sample App

    Help

    Get help on the Ruby on Rails Tutorial at the Rails Tutorial help section. To get help on this sample app, see the Ruby on Rails Tutorial book.

    10. ,ħĥȁƷďχcʡ Google ChromeXȘΪƃƷďcʡ SafariĊ"đ Chrome ɥșˁŁȂʬȾЀ 3.4. çĎR³A“ĜƩƨ - 81 'ĢĉX 3.26@çÚ HTML ĿïĜ“>”Ʃƨ GREEN app/views/static_pages/about.html.erb About | Ruby on Rails Tutorial Sample App

    About

    The Ruby on Rails Tutorial is a book and screencast series to teach web development with Ruby on Rails. This is the sample application for the tutorial.

    ʜđɭͤ˹I̞ιΣ/GREEN 'ĢĉX 3.27GREEN $ bundle exec rake test 3 tests, 6 assertions, 0 failures, 0 errors, 0 skips 3.4.3. ¡šo;­ Rubyƕï ¦ʲª"ɖȪ̩Ũ˾s/Ƒĥ2ƧƴHcʡ Rails ǧ§ćû³`ʠƳ/àʡʬϷ϶ΣΪ8Ϸ϶ ʬŠňχȘ˵ϴƛʬ HTMLɥȤ\ʜ— Rails ʬƆħ'ġ̖EʼȤʹħώύģ • Ϸ϶ʬȾЀ•(XŁȘ ɏ ɂʬ • ɞȾЀχȤ“Ruby on Rails Tutorial Sample App” • Ȃ HTML ̀ȴđɞϷ϶χύģĒ—ʜ/ ύģʬEʼέÓ/Ƒύͅʬ“̢ͅƴύģ”Don’t Repeat Yourselfˣˎ DRY͞Ȫ̩ͅρʉ DRY Í žÎǢύģʬEʼȣëƴHͅΦ̼ª ̩̋Žʬɭͤˀ͒șˁʬȾЀAʈɗˀ ΣÎϪύģʬ˟ əÊȘͅб 8Eʼ͔Ϸ϶ʬȾЀʶΈȱȘ ɂʬΪɂƴHŗ̞ȠňȕĒÎǢ ύģʬEʼ/ đΪΣːͅđ͉ďcʡš~Ɓ RubyEmbedded RubyȍʈЄϷ“Ŭ´”Ϸ϶û“ƒ4”Ϸ϶ʬȾ ЀȤ ׳ʬφšτƴHŗcʡ Rails ǫeʬ ʒ¥ʬ™ȁ provideđɞϷ϶͝łéʬȾ ЀιΣLj home.html.erb ͉ďȾЀʬ“Home”ǞƳEʼɴà 3.28 ƺˁʬEʼƴHàGʶ Ϊ™ȁʬ `ʡ 'ĢĉX 3.28ôƭ3ė;­ Ruby 'ĢĜƮƩŝv GREEN app/views/static_pages/home.html.erb 82 - Į 3 ī }êƦ³ĜƩƨ <% provide(:title, "Home") %> <%= yield(:title) %> | Ruby on Rails Tutorial Sample App

    Sample App

    This is the home page for the Ruby on Rails Tutorial sample application.

    đΪɛEʼƴH˟ ɐcʡ/š~Ɓ RubyƵ̕ˣˎ ERbʜđaŷͨʺο">% HTML ͉ďȃIʬ ǁŞêȘ .html.erb /ERb Ș"̏Ϸɳ±³ƛŠň#ͅcʡʬɏȲ˭̃11 ϶ʬEʼ <% provide(:title, 'Home') %> ιΣ <% … %> ͱʡ Rails ʬ provide ™ȁLjĻ˞ "Home" ΃́ :title12 ʈëđȾЀƴHcʡ˨ Wʬ˞ä <%= … %>ιΣ Ruby ʬ yield ™ȁLjȾЀǬ~ɏȲ 13 <%= yield(:title) %> | Ruby on Rails Tutorial Sample App Ϊˋš~ Ruby EʼʬȈƁ½¥đ4<% … %> Þǀ̼…ʬEʼ <%= … %> *Rǀ̼…ʬEʼ̖ RLjǀ̼ʬ̀ȷǬ~ɏȲȣ˼ƒ¦ʬϷ϶ûGª ɂΣʜđȾЀ׳ʬφšιΣ ERb ³ƛʠ Ƴ ƴHàGΦ̼ª ̩̋Žʬɭͤˀ͒ ——ɭͤΩ̞ιΣGREEN 'ĢĉX 3.29GREEN $ bundle exec rake test 3 tests, 6 assertions, 0 failures, 0 errors, 0 skips ʈëǚʉʴéʬȈƁkǹ“Ŭ´”Eʼɴà 3.30û“ƒ4”Ϸ϶Eʼɴà 3.31 'ĢĉX 3.30ôƭ3ė;­ Ruby 'ĢĜ“£S”Ʃƨŝv GREEN app/views/static_pages/help.html.erb <% provide(:title, "Help") %> <%= yield(:title) %> | Ruby on Rails Tutorial Sample App 11. ΩȤ ˋÖɑΥʬɏȲ˭̃Ș Hamlƴ=ƑąɑʡΣđΪɂʬ¡˴ǿːcʡĩèε 12. ˾Јŋʬ Rails ŽÔ̕à̞͋ƒΪόŷͨcʡ content_foràȘľđ Asset Pipeline ȤʁϝЀprovide ™ȁȘȢE Ȉɇ 13. IJȷaĽΣ Rubyà̞Rʘɭ Rails ȘLjŠň“Ǘ~”½ĖʬΪ%Ƭ*ŌΣcʡ Rails ŽÔŷʡƖʺοΪ ʁ 3.4. çĎR³A“ĜƩƨ - 83

    Help

    Get help on the Ruby on Rails Tutorial at the Rails Tutorial help section. To get help on this sample app, see the Ruby on Rails Tutorial book.

    'ĢĉX 3.31ôƭ3ė;­ Ruby 'ĢĜ“>”Ʃƨŝv GREEN app/views/static_pages/about.html.erb <% provide(:title, "About") %> <%= yield(:title) %> | Ruby on Rails Tutorial Sample App

    About

    The Ruby on Rails Tutorial is a book and screencast series to teach web development with Ruby on Rails. This is the sample application for the tutorial.

    ̣ɘƴHLjϷ϶ȾЀʬ׳φšχǞƳ/ ERbʜđçϷ϶ʬŠň˨W϶Ϊɂ <% provide(:title, "The Title") %> <%= yield(:title) %> | Ruby on Rails Tutorial Sample App Contents *ŗȘͭƺȤʬϷ϶̀ȴχȘ ̤ʬºǖ title ȾˢʬŠňÞȤ body ȾˢʬŠňȤ8Ŧ¥ "/ǫ՗‚ʡʬ̀ȴRails ǫe/ ʒ¥ʬũŚȃIê" application.html.erbƴHđ 3.4 ̩ύú ê/ΪȃIʜđǹĉȱ 84 - Į 3 ī }êƦ³ĜƩƨ $ mv layout_file app/views/layouts/application.html.erb ̫ƬcʡΪũŚƴHͅLjЎ͒ʬȾЀǞƳª϶•ɛEʼcʡʬš~Ɓ Ruby <%= yield(:title) %> | Ruby on Rails Tutorial Sample App kǹ냦ʬũŚȃIIJEʼɴà 3.32 ƺˁ 'ĢĉX 3.32Ɔ čĥ©ėĜņĪ¡š GREEN app/views/layouts/application.html.erb <%= yield(:title) %> | Ruby on Rails Tutorial Sample App <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> <%= yield %> ɩƮ…Ȥ ̼ɟΚʒɚ <%= yield %> Ϊ̼Eʼʬ`ʡȘLjɞϷ϶ʬŠňǬ~ũŚɥƖͅ/͍ľʬ†\ŃʜΣːƴHÞϳʺοđũŚ cʡΪ̼Eʼë͞ϝ /static_pages/home ȒRLj home.html.erb ʬŠňΕǞƳ HTMLʈëǬ~ <%= yield %> ƺđʬY̐ ῼɩƮЎ͒ʬ Rails ũŚȃIΩȤ϶Ϊ•̼Eʼ <%= stylesheet_link_tag ... %> <%= javascript_include_tag "application", ... %> <%= csrf_meta_tags %> Ϊ•̼Eʼʬ`ʡȘƂ~ŷʡʬɂƁ̿û JavaScript ȃIAsset Pipeline ʬ φš5.2.1 ̩R@˽ Rails ʬ csrf_meta_tags Ȉɧ`ʡȘς}“Ώ˚ͮɤTλ”Cross-Site Request Forgeryˣˎ CSRF ˋ ƥƮ̏̂Ǻ˜ ʜđEʼɴà 3.283.30 û 3.31 ʬŠňΩȘûũŚȃI˨Wʬ HTML ̀ȴƺGƴHͅLjŁȂʬ̀ȴ ¢ϪÞiʥϳͅʬŠňɴʞëʬ͉ďIJEʼɴà 3.333.34 û 3.35 ƺˁ 'ĢĉX 3.33\ƢÚĜ HTML ĿïkĜƮƩ GREEN app/views/static_pages/home.html.erb <% provide(:title, "Home") %>

    Sample App

    This is the home page for the Ruby on Rails Tutorial 3.4. çĎR³A“ĜƩƨ - 85 sample application.

    'ĢĉX 3.34\ƢÚĜ HTML ĿïkĜ“£S”Ʃƨ GREEN app/views/static_pages/help.html.erb <% provide(:title, "Help") %>

    Help

    Get help on the Ruby on Rails Tutorial at the Rails Tutorial help section. To get help on this sample app, see the Ruby on Rails Tutorial book.

    'ĢĉX 3.35\ƢÚĜ HTML ĿïkĜ“>”Ʃƨ GREEN app/views/static_pages/about.html.erb <% provide(:title, "About") %>

    About

    The Ruby on Rails Tutorial is a book and screencast series to teach web development with Ruby on Rails. This is the sample application for the tutorial.

    kǹΪ•͉ďëЄϷ“Ŭ´”Ϸ϶û“ƒ4”Ϸ϶șˁʬŠňΩû'ª ɂXȘɥȤĥŒύģŠň/ ˾Јõ͡ƴHÉgȘ¿šˣÃʬύȴ*ňȕ—ϖƺGƼ͒ͅʷ̋Žɭͤ˹IȤ/ɭͤƴHŗȌϳ ƻ³ɉȼɞϷ϶ʶȤɥȤϖͫ¡ȧϣɛƻ³ɉȼΩˤϯXȘƈŷʡȆ×ħ'ëƧ‘ŗé /ƴHÞϳЈ͟ɭͤ˹IȘïΩ̞ιΣÉà 'ĢĉX 3.36GREEN $ bundle exec rake test 3 tests, 6 assertions, 0 failures, 0 errors, 0 skips ɭ̞ͤ͟ȔEʼŁɗˀX̣Œ̞ǫЌɗˀʬà̞Ɵ̖Ωǫe/ŀϢNJǩȉς}Gë—ʜϝ Ѐ 3.4.4. ŤŇöŹĘ ƴHkǹ/̏˚ʬϷ϶*Ϻ¤ŽĶ̋Žɭͤ/đ̄̆'ªƴH̐͝ͅŷʡʬɄΐʢ 1.3.4 ̩û 2.2.2 ̩ʬsɧ ɂƴHͅkǹ routes.rb ȃILjɄΐƏ / ǙìƴHζǕʬϷ϶ΪόƴHͅǙìª϶ żʬЄϷƴΩż͖Lj 3.1 ̩ɳ±ʬ hello ³`Bŷʡʬǧ§ć¢ϪIJEʼɴà 3.37 ƺˁƴHͅ Lj̢³ʠƳʬ get ͈žEʼɴà 3.5ǹƳ root 'static_pages#home' 86 - Į 3 ī }êƦ³ĜƩƨ ƴHLj static_pages/home ǹƳ static_pages#homeˀiιΣ GET ͮɤ͞ϝ / ȒR9́ϴƛϷ϶ΐʢć ʬ home ³`ġʞkǹΐʢëЄϷIJď 3.7 ƺˁɩƮkǹΐʢ'ë/static_pages/home ŗȌɧ͞ϝ / 'ĢĉX 3.37ÀöŹĘÅlƮƩ config/routes.rb Rails.application.routes.draw do root 'static_pages#home' get 'static_pages/help' get 'static_pages/about' end v 3.7wöŹĘ ãĥĜƮƩ 3.5. –Ŀ ơʬȱͭȪ˜•(ɥȤs>% ƴHBϴƛϷ϶ŽĶȣ냦ʬΩ•(ȘϴƛŠňʬϷ϶ΣB̿϶ ȱʶƴHcʡ/ Rails ʬǧ§ć³`û͉ďʜđƴHŨ˾àGì̏˚ɳ±KƮʬ³ƛŠň/Ȫ ,ʬë̆ŠňRõ͡aƜ%ɳ± đ̄̆'ªƴH̪ ʁȒϞLjǹ³ǫ9¦#ЀšǷʈëՅèŲ¦#šǷđ 3.2 ̩ƴH"ϴƛϷ ϶ʬŽÔţ` ż/  Git ȇšǷđŽÔʬΣːIJȷaΩɥȤǫ9τ%{ȱs ɐǫ9ðĊ"ƴ HŨ˾ŁƳ/ 8ţ` $ git add -A $ git commit -m "Finish static pages" 3.5. –Ŀ - 87 ʈëcʡ 1.4.4 ̩@˽ʬȈɧLjǹ³èŲ¦#šǷ $ git checkout master $ git merge static-pages ɞɐŁƳ 8ţ`ëȣıLjEʼǨδ¦άːCŶIJȷaǚʉ 1.4.3 ̩ʬəЊs/άːCŶđ Bitbucket  $ git push ƴΩż͖aLjΪŷʡφ̑¦ Heroku  $ bundle exec rake test $ git push heroku đφ̑'ªƴH{Φ̼ɭͤ˹I——ΪȘ ı+ƫ 3.5.1. ُêīM! • ƴH˟ɐ@˽BϲŽĶ ż ȇ Rails ŷʡʬŁȂΣːºǖŀ̓ƺϳʬ gemLjŷʡǨδ¦ά ːCŶGÑφ̑¦ʠ:ʛĝ • ǀ̼ rails generate controller ControllerName úFRʠƳ ȇǧ§ ć • đ config/routes.rb ȃIł&/ȇΐʢ • Rails ʬ͉ďàGºñϴƛ HTML Ñš~Ɓ Ruby EʼERb • ɭͤ˹I̞І³ƴHŽÔȇ°̞́ƴHύȴʬ̢jGÑǝ̰ĉƇ • ɭͤІ³ŽÔcʡ“ν˲-×̉-ύȴ”Ɠʛ • Rails ʬũŚł&Ϸ϶‚ʡʬ̀ȴàGÎϪύģ 3.6. ļ BΪGëƴż͖đÃʖʬ#ЀšǷs˸+ $ git checkout static-pages $ git checkout -b static-pages-exercises Ϊ%sŗRûȪ,ɗȃ:ʠ˕/ ˸+sŁëàGLjʴŷʬšǷǨδ¦άːCŶIJȷȤάːCŶʬͦ # 9Į ļk $ git commit -am "Eliminate repetition (solves exercise 3.1)" # 9Į ļk $ git add -A $ git commit -m "Add a Contact page (solves exercise 3.2)" $ git push -u origin static-pages-exercises $ git checkout master "/̄̆ë϶ʬŽÔȣë əޛǞ¦#šǷXèŲG}ûɗȃ:ʠ˕đë϶ʬ˜̩ cʡʬšǷûǫ9ɯƣȤƺéXěȪƞƬȘ ̤ʬ 88 - Į 3 ī }êƦ³ĜƩƨ 1. aà̞ɩƮ¦/ϴƛϷ϶ǧ§ʬɭͤEʼɴà 3.22Ȥ8ύģɞȾЀɭͤχȤ“Ruby on Rails Tutorial Sample App”ƴHͅcʡʒɚʬ™ȁ setup ÎϪύģΪ™ȁđɞɭͤΦ̼'ªǀ ̼ͮaˀ͒Eʼɴà 3.38 ʬɭͤA̞ιΣEʼɴà 3.38 cʡ/ Ńd×ώ2.2.2 ̩ˣ Ã@˽Σ4.4.5 ̩RΫ ə@˽ΪɛEʼΩcʡ/Ļ˞ Ǭoǵ`4.2.2 ̩Rs@˽ 2. "Ϊɼˁŷʡɳ± “̘˭”Ϸ϶14 ÏʉEʼɴà 3.13{̋Ž ɭͤɉȼϷ϶ʬȾЀȘï " “Contact | Ruby on Rails Tutorial Sample App”B̖ˀł /static_pages/contact ŌŷʬϷ϶Șïļđ LjEʼɴà 3.39 ʬŠňŽ~“̘˭”Ϸ϶ʬ͉ď͔ɭͤιΣɩƮΪ˸+Șʖ˘ʬƺGEʼ ɴà 3.39 ʬEʼRƋþEʼɴà 3.38 ʬɭͤ 'ĢĉX 3.383ėƌėôƭĜƦ³ƩƨËNrąŨ GREEN test/controllers/static_pages_controller_test.rb require 'test_helper' class StaticPagesControllerTest < ActionController::TestCase def setup @base_title = "Ruby on Rails Tutorial Sample App" end test "should get home" do get :home assert_response :success assert_select "title", "Home | #{@base_title}" end test "should get help" do get :help assert_response :success assert_select "title", "Help | #{@base_title}" end test "should get about" do get :about assert_response :success assert_select "title", "About | #{@base_title}" end end 'ĢĉX 3.39“ŋĵ”ƩƨĜA“ app/views/static_pages/contact.html.erb <% provide(:title, "Contact") %>

    Contact

    Contact the Ruby on Rails Tutorial about the sample app at the contact page.

    14. Ϊ˸+Rđ 5.3.1 ̩ŁƳ 3.6. ļ - 89 3.7. ƱĺąŨ¿ë Ϊ ̩ζͯ@˽Ȫ,ψį͉Ͽcʡʬɭͤ̐͝ºñȈ϶Šň ĞƆʏιΣûĪͻNjõːŵ3.7.1 ̩ ΣɻɭͤĪͻɯƣͱʡΎΒʬȈɧ3.7.2 ̩ ̢³ɭͤΦ̼ːŵɉɭ¦ȃIȤ×»ë̢³ Φ̼ʴŷʬɭͤ3.7.3 ̩Ϊ ̩cʡʬEʼʴŌЌ˴ǻđΪόÞȘ"/ȼϠȈgʜđŲȧȦa̞ ʞ͍ Ϊ ̩ŷͨđ#šǷkǹ $ git checkout master 3.7.1. MiniTest ÁmĨ§ "/͔ Rails ʬɭͤεȒșˁ˲̨ų̂̉ƴż͖ađɭͤΛ´ȃI±~Eʼɴà 3.40 ʬŠň15 z š¤ʡEʼɴà 3.2 ʬ minitest-reporters gem 'ĢĉX 3.40ƓŇąŨãĥĸœoŃœ test/test_helper.rb ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require "minitest/reporters" Minitest::Reporters.use! class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical # order. fixtures :all # Add more helper methods to be used by all tests here... end kǹëđ5˝ IDE șˁʬǽȷIJď 3.8 ƺˁ v 3.8wĬ IDE ąŨĘĸbŃ 15. ΪɛEʼȍcʡ/ÃƂäƊƁĻ˞ Ðcʡ/ÒƂäƊƁĻ˞ Ċ" rails new úFʠƳʬȃIcʡÃƂäĻ˞  ̖ MiniTest NjõːŵʬȃɈcʡÒƂäđ Ruby EʼɲʡˋƊƁʬĻ˞ Ƒŭ͆ͩƧÏ͆ 4.2.2 ̩ 90 - Į 3 ī }êƦ³ĜƩƨ 3.7.2. ŰėŸźƦƲĨ§ IJȷȤϖͫƵ̕ɭͤĪͻɭͤΦ̼ːŵRșˁͱʡΎΒBĪͻʬɭͤŽĶ ʳβɹ¦ŷʡEʼͱʡ ΎΒŌȼDžϝЀȱͭƑȤʡXđȺ8˭̃ºǖ5˝ IDER ʳβɹ¦ŷʡʬEʼGÑç gemºǖ RailsșˁʬŠňƍƍƑĥIJȷϝЀÔʠđŷʡEʼ̖Șľʬf΄Iτ%Šň Ƞĥ ƴHàGΣɻͱʡβΒșˁϳͅʬŠň"ɘƴHͅcʡEʼɴà 3.2 ʬ mini_backtrace gemʈ ëŒ̐͝ϴЎːŵđ5˝ IDE ħĥȁϳͅʬŠňχºñĻ˞ “rvm”ǙʬȘ Ruby Version ManagerƺGƴż͖cʡEʼɴà 3.41 ʬϴЎːŵLjΪ8ŠňΣɻǢ 'ĢĉX 3.41ĈPŰėŸźƦƲĨ§ƂČ RVM Ğ>ĜA“ config/initializers/backtrace_silencers.rb # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't # wish to see in your backtraces. Rails.backtrace_cleaner.add_silencer { |line| line =~ /rvm/ } # You can also remove all the silencers if you're trying to debug a problem # that might stem from framework code. # Rails.backtrace_cleaner.remove_silencers! IJΪɛEʼʬɩϋƺͭɳ±ϴЎːŵëͅύóȪĒȥ²ć 3.7.3. 3ė Guard ŐRąŨ cʡ rake test úFȤ ʁƑʅ=ơȘͅ›Ǟ¦úF̼ʈëƻ³Φ̼ɭͤ"/ς}ΪˋgƴHàG cʡ Guard ̢³Φ̼ɭͤGuard Rʰ͉ȃI˭̃ʬ׳qIJakǹ/ static_pages_controller_test.rbτ% Guard ÞRΦ̼ΪȃIʬɭ̖ͤƴHΩàGψ̐ Guard͔ ľđ home.html.erb ȃÍkǹë*̢³Φ̼ static_pages_controller_test.rb Eʼɴà 3.2 Ũ˾ºñ/ guard gemƺGƴHÞϳ¡Ķ»Éà $ bundle exec guard init Writing new Guardfile to /home/ubuntu/workspace/sample_app/Guardfile 00:51:32 - INFO - minitest guard added to Guardfile, feel free to edit it ʈëŒ̋ΜʠƳʬ Guardfile ȃI͔ Guard đϱƳɭͤû͉ďÔʠ×»ëΦ̼ɗˀʬɭͤIJEʼɴà 3.42 ƺˁΪȃIʬŠňƑϙ̖ϳͅЌ˴ʺ͠ƺGƴż͖ʳǦģ§˪΀ 'ĢĉX 3.426Õ Guardfile # Defines the matching rules for Guard. guard :minitest, spring: true, all_on_start: false do watch(%r{^test/(.*)/?(.*)_test\.rb$}) watch('test/test_helper.rb') { 'test' } watch('config/routes.rb') { integration_tests } watch(%r{^app/models/(.*?)\.rb$}) do |matches| "test/models/#{matches[1]}_test.rb" end watch(%r{^app/controllers/(.*?)_controller\.rb$}) do |matches| 3.7. ƱĺąŨ¿ë - 91 resource_tests(matches[1]) end watch(%r{^app/views/([^/]*?)/.*\.html\.erb$}) do |matches| ["test/controllers/#{matches[1]}_controller_test.rb"] + integration_tests(matches[1]) end watch(%r{^app/helpers/(.*?)_helper\.rb$}) do |matches| integration_tests(matches[1]) end watch('app/views/layouts/application.html.erb') do 'test/integration/site_layout_test.rb' end watch('app/helpers/sessions_helper.rb') do integration_tests << 'test/helpers/sessions_helper_test.rb' end watch('app/controllers/sessions_controller.rb') do ['test/controllers/sessions_controller_test.rb', 'test/integration/users_login_test.rb'] end watch('app/models/micropost.rb') do ['test/models/micropost_test.rb', 'test/models/user_test.rb'] end watch(%r{app/views/users/*}) do resource_tests('users') + ['test/integration/microposts_interface_test.rb'] end end # Returns the integration tests corresponding to the given resource. def integration_tests(resource = :all) if resource == :all Dir["test/integration/*"] else Dir["test/integration/#{resource}_*.rb"] end end # Returns the controller tests corresponding to the given resource. def controller_test(resource) "test/controllers/#{resource}_controller_test.rb" end # Returns all tests for the given resource. def resource_tests(resource) integration_tests(resource) << controller_test(resource) end ϶Ϊ̼ guard :minitest, spring: true, all_on_start: false do R͔ Guard cʡ Rails ǫeʬ Spring ȥ²ć“Œ±ΙȒϞ̖ó³ȒΦ̼Ȃɭͤ˹I 92 - Į 3 ī }êƦ³ĜƩƨ cʡ Guard Ȓ"/ς} Spring û Git Ôʠ˕ŷͨLj spring/ ȃIĬ±¦ .gitignore ȃI͔ Git ƚ ʦΪȃIĬđ5˝ IDE ͅΪ%s • ʁ˜ȃIɮ͊ćã͌ʬБΖďȾIJď 3.9 ƺˁ • ζǕ“Show hidden files”șˁϭ̷ȃI͔ .gitignore ȃI—ʜđŷʡʬɄʲƉIJď 3.10 ƺ ˁ • ҘƾŽ .gitignore ȃIď 3.11Ž~Eʼɴà 3.43 ʬŠň v 3.9Û*ĆŞrĜƳŽvô ƒ‡½ 3.7. ƱĺąŨ¿ë - 93 v 3.10ãĥƣŗÛ* v 3.11ƌ¤ƣŗĜ .gitignore Û*Dĕ 94 - Į 3 ī }êƦ³ĜƩƨ 'ĢĉX 3.43À Spring ĈPM .gitignore Û* # See https://help.github.com/articles/ignoring-files for more about ignoring # files. # # If you find yourself ignoring temporary files generated by your text editor # or operating system, you probably want to add a global ignore instead: # git config --global core.excludesfile '~/.gitignore_global' # Ignore bundler config. /.bundle # Ignore the default SQLite database. /db/*.sqlite3 /db/*.sqlite3-journal # Ignore all logfiles and tempfiles. /log/*.log /tmp # Ignore Spring files. /spring/*.pid Ž`Ȫ,ȒSpring ȥ²ćΩȤʁwƠžȤȒ Spring ΫːRȆǑƱɭͤʬΦ̼κźIJȷaÔʜɭͤ× ƒžŭ̊Ʊȣıȼʶ˭̃ΫːȊɩ 3.4IJȷϳͅƒǢ Spring Ϋː ߥ 3.4Unix ƇĨ đ Unix ˨˭̃dIJ Linux û OS Xʡƹû˭̃ǀ̼ʬK²χđº̧̓ıʬňćΪňćß“Ϋ ː”process̫Ƭȼʶ˭̃ʬƺȤΫːàGǀ̼ ps úFŲǙł aux Ïȁ $ ps aux ̫ƬΣɻΝ—ʬΫːàGcʡ Unix ˥οǵ`|Lj ps úFʬ̀ȷŚ grepΫ̼ɏƁ¼ψ $ ps aux | grep spring ubuntu 12241 0.3 0.5 589960 178416 ? Ssl Sep20 1:46 spring app | sample_app | started 7 hours ago șˁʬ̀ȷȤΫːʬφšͩ˺jƣ…ȣύͅʬȘ˟ ȁĻÉΫːʬ IDˣˎ pid̫ͅ˼ɖ ƬͅʬΫːàGcʡ kill úFìǙłʬ pid Ôδ kill jäƤťȘ 9 $ kill -9 12241 ƒϜÃΫːdIJŒcʡʬ Rails ȥ²ćΫːàǀ̼ ps aux | grep server úFDž¦ pidƴǨ ̯cʡΪˋȈɧΣȤȒȣı̞DŽώƒϜΫːêˋºñʒłȃȪʬΫːdIJƒϜ˭̃ƺȤʬ spring ΫːϏŌ SpringЄ{ŷͨŕͤcʡ spring úFƒϜΫː $ spring stop ΣȤȒΪ%sɥʡτ%àGcʡ pkill úFƒϜƺȤê"“spring”ʬΫː 3.7. ƱĺąŨ¿ë - 95 $ pkill -9 -f spring ÞͅÔʜ̿ʜžŭƵ̕Ϋːϴɖ/ȣıǀ̼ ps aux úFʶʶƜ%ĉ2ʈëŒǀ̼ kill -9 Ƶ pkill -9 -f úFƒϜΫː ψ̐ı Guard 'ëŷͨƾŽ ȇ˼˝˖Úû 1.3.2 ̩ó³ Rails ȥ²ćʬsɧ ɂđ…ǀ̼ΰ úF $ bundle exec guard Eʼɴà 3.42 ʬ͈žϏŌȪ,s/P»dIJkǹǧ§ćëR̢³Φ̼ϱƳɭͤIJȷƬΦ̼ƺȤɭ ͤđ guard> ˼˝ǚĉΔϗȤȒRʶ¦ ϖͫͭήǦ Spring ȥ²ćĪͻŒɐǚĉΔϗŗ̞͍ ΪϝЀ ̫Ƭγ— Guardǚ Ctrl-D ϗIJȷƬ" Guard ɳ±…Dʬ¼ψćÏʉEʼɴà 3.42Guard ʬͭȔȃI û̇ě 96 - Į 3 ī }êƦ³ĜƩƨ Į 4 ī Rails ŌkĜ Ruby Ȥ/˟ 3 ˜ʬdĺsϓĘȪ˜ͅ@˽ 8Ō Rails ȱͭƑύͅʬ Ruby ʺ͠Ruby ͪ͏ʬʺ͠ʁƑĥ ΣŌ Rails ŽÔ̖̕͏ϳͅǣǭʬƑŒƴHϊʡʬȈƁȤ¥4ŭ͈ʬ Ruby Ľ+ΣːȪ˜ʬʲȾȘ˥ aȤɥȤ Ruby ̋ː˾Јχƒ͔aǣǭ̋Ž Rails ŷʡƺϳʬ Ruby ʺ͠Ϊ ˜ʬŠňƑĥ˟ ɐϠͯ ̞Łǣǭ*ɥƒ˭ë̆ʬ˜̩ƴR˾ŭǫ¦Ȫ˜ʬŠň 4.1. •Š Bª ˜ƒʺÉcŁƲ Ruby ͪ͏ƴH*àG ż Rails ŷʡʬЋȹGÑ̋ŽɭͤƴHf΄4, ǫeʬɭͤEʼƒ¦ϖͫjƣʈë͔ɭͤ˹IιΣXȘƴH̞ơȘΪɂƺGΪ ˜ȞȒ͙̏ ˚ŽÔ̖ͅɗ͉ƴHʬʻ̚——Ruby ͪ͏ ª ˜ȩřƴHkǹ/•(ȘϴƛŠňʬϷ϶͔ľHcʡ Rails ũŚÎϪ͉ďʬύģƴHcʡʬũ ŚIJEʼɴà 4.1 ƺˁûEʼɴà 3.32 ɂ 'ĢĉX 4.1čĥ©ėĜņĪ¡š app/views/layouts/application.html.erb <%= yield(:title) %> | Ruby on Rails Tutorial Sample App <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> <%= yield %> ƴHLjɩƮ¯ϱđΰEʼʬΪ ̼ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> Ϊ̼Eʼcʡ Rails Š̐ʬȈɧ stylesheet_link_tagͩ˺jƣÏ͆ Rails API ȃɈđƺȤĹ@˨ėƂ ~ application.cssŌȤ˾Јʬ Rails ŽÔ̕ȱͭΪ̼EʼʶΈȱƑˣÃXȘ…̣ŒȤĈ Ruby ʺ ͠ʁà̞R͔aČƩ Š̐ʬ Rails ȈɧͱʡȈɧȒʡǖä˞äûýŪΪ•ʁȪ˜χR@˽ Rails Ϫ/ǫeƑĥŠ̐ʬȈɧeƴHđ͉ďcʡ'ĤΩx͛ƴH̢ŧł&̢ŧł&ʬȈɧßΛ´Ȉɧ helper"/ͭȔIJ]̢ŧł&Λ´ȈɧƴHȱʶʶEʼɴà 4.1 ȾЀτ ̼ <%= yield(:title) %> | Ruby on Rails Tutorial Sample App 97 Ϊ̼Eʼͅɤɞ͉ďχͅcʡ provide Ȉɧł&ȾЀdIJ <% provide(:title, "Home") %>

    Sample App

    This is the home page for the Ruby on Rails Tutorial sample application.

    τ%IJȷƴHǫeȾЀRƜɂ÷ ȾЀ ̦χºñ €‚φšIJȷƬȠ†\8àGŒ±׳ʬ φšƴHđũŚʡ/őLJťěȪŨ˾Ńʜ/ΪɂʬȾЀIJȷđ͉ďͱʡ provide Ȉɧ* ŗȘǫe׳ʬφšτ%ƒ¦ʬȾЀR×Ƴ | Ruby on Rails Tutorial Sample App ȾЀȤ€‚φšXª϶Ωșˁ/˙˷ "/͍ΪϝЀƴH̢ͅł& Λ´Ȉɧúê" full_titleIJȷ͉ďɥȤł&Ϸ϶ʬȾЀ full_title ΨĉȾЀʬ€‚φšÉ“Ruby on Rails Tutorial Sample App” IJȷł&/žđ׳φšë϶±  ˙˷IJEʼɴà 4.2 ƺˁ1 'ĢĉX 4.2 full_title ſSÞă app/helpers/application_helper.rb module ApplicationHelper # öǹwĜƩƨƄsÚĜôƭ def full_title(page_title = '') base_title = "Ruby on Rails Tutorial Sample App" if page_title.empty? base_title else "#{page_title} | #{base_title}" end end end ʜđΪΛ´Ȉɧł&ı/ƴHàGʡľȱˣ»ũŚLj϶Ϊ̼ <%= yield(:title) %> | Ruby on Rails Tutorial Sample App ǹƳ <%= full_title(yield(:title)) %> IJEʼɴà 4.3 ƺˁ 'ĢĉX 4.33ė full_title ſSÞăĜņĪ¡š GREEN app/views/layouts/application.html.erb 1. IJȷΛ´ȈɧȘϏŌȺʒłǧ§ćʬŷͨLjľǻΫͨǧ§ćŌŷʬΛ´ȃIdIJ"ϴƛϷ϶ǧ§ć żʬΛ´Ȉ ɧ ̦ǻđ app/helper/static_pages_helper.rb đΪdĺƴHƬđƺȤϷ϶χcʡ full_title Ȉɧƺ Gͅǻđ ʒɚʬΛ´ȃIÉ app/helper/application_helper.rb 98 - Į 4 ī Rails ŌkĜ Ruby <%= full_title(yield(:title)) %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> <%= yield %> "/͔ΪΛ´ȈɧΈ`ʡƴHͅđЄϷʬ͉ďLjƖͅʬÃ͢“Home”¢ǢÞiʥȾЀʬ€‚φš Є{ƴHͅkǹɭͤEʼIJEʼɴà 4.4 ƺˁˀ͒ȾЀɥȤ "Home"ɩƮIJȷas/ª ˜ʬ ˸+ǚʉEʼɴà 3.38 kǹ/ɭͤʜđͅLjł& @base_title ×ώʬ setup Ȉɧ¢Ǣ 'ĢĉX 4.46ÕƮƩĜôƭąŨ RED test/controllers/static_pages_controller_test.rb require 'test_helper' class StaticPagesControllerTest < ActionController::TestCase test "should get home" do get :home assert_response :success assert_select "title", "Ruby on Rails Tutorial Sample App" end test "should get help" do get :help assert_response :success assert_select "title", "Help | Ruby on Rails Tutorial Sample App" end test "should get about" do get :about assert_response :success assert_select "title", "About | Ruby on Rails Tutorial Sample App" end end ƴHͅΦ̼ɭͤ˹Iˀ͒Ȥ ɭͤĪͻ 'ĢĉX 4.5RED $ bundle exec rake test 3 tests, 6 assertions, 1 failures, 0 errors, 0 skips "/͔ɭͤιΣƴHͅLjЄϷ͉ďʬ provide τ̼¢ϪIJEʼɴà 4.6 ƺˁ 'ĢĉX 4.6ÐƩƨôƭĜƮƩŝv GREEN app/views/static_pages/home.html.erb 4.1. •Š - 99

    Sample App

    This is the home page for the Ruby on Rails Tutorial sample application.

    ʜđɭͤŷͨàGιΣ/ 'ĢĉX 4.7GREEN $ bundle exec rake test ɩƮ'ªΦ̼ rake test Ȓχșˁ/ιΣûĪͻɭͤʬȁώ"/̼ȃˣɪBΪGëχRʵʦΪ8ȁ ǟ ûƂ~ŷʡʬɂƁ̿τ̼Eʼ ɂEʼɴà 4.2 ʬŠňŌȤ˾Јʬ Rails ŽÔ̕ȱͭ*ƑˣÃX…Ƒĥ ύͅʬ Ruby ʺ͠ ɏĖȈɧł&àζʬȈɧÏȁɩϋȪĒ×ώ΃oũœoɬːǧ§Ļ˞ ǬoûΨĉoȪ˜R @˽Ϊ8ʺ͠ 4.2. ‹ĭoÞă ƴHĽ+ Ruby #ͅcʡʬţ†Ș Rails ǧ§áľȘʡȱû Rails ŷʡ96ʬúF̼ţ†đ 2.3.3 ̩@˽ Σǧ§áě4 Ruby ʬ96ːŵirbŽÔĊɘ̞cʡ Ruby ͪ͏ʬφ°̞4.4.4 ̩R@˽ǧ§ áΩàG͞ϝ Rails ʛĝ IJȷcʡ5˝ IDEƴż͖cʡ 8 irb ψ̐ÏȁcʡˣÃʬ nano ȃȪ̋ΜćLjEʼɴà 4.8 ʬŠň Ž~ŇʲƉόʬ .irbrc ȃI 2 $ nano ~/.irbrc Eʼɴà 4.8 ʬŠň`ʡȘˣ» irb ǫˁ˞Gшʡ 8ʅ=ʬ̢³̍Ϋ̼" 'ĢĉX 4.8ĈP irb ƓŇ ~/.irbrc IRB.conf[:PROMPT_MODE] = :SIMPLE IRB.conf[:AUTO_INDENT_MODE] = false ˥±ɥ±Ϊ8̐͝ǧ§ćʬó³ȈɧχȘđúF̼ǀ̼϶ʬúF $ rails console Loading development environment >> Ў͒Ƨ‘ǧ§áđŽÔʛĝó³ΪȘ Rails ł&ʬʖ˘ʛĝ' ÝĤȘɭͤʛĝûʠ: ʛĝΪʛĝʬ½¥ŌȪ˜ύͅ7.1.1 ̩Rͩ˺@˽ ǧ§áȘĽ+ʬıţ†aàGŘƧĒǥ˯ľʬʡɧ¥Ǐƕa•(RʽĕK]̈́IJȷđǧ§ áν¦/ϝЀàGǚ Ctrl-C ϗ̀ȯƈªǀ̼ʬǵ`Ƶ̕ǚ Ctrl-D ϗʳǦγ—đϠͯȪ˜ë̆Šňʬ 2. ͣ̕ɩ ŽŁëđúF̼ǚ Ctrl-W ϗiļʈëǚĉΔϗˀ͒iļđǙłʬȃIȣëǚ Ctrl-E ϗγ— nano 100 - Į 4 ī Rails ŌkĜ Ruby ΣːaRÔʜȼϠ Ruby API ƑȤŬ´API ȤƑĥjƣƵ͛ĩĥ/dIJIJȷƬΫ ə/͍ Ruby Ļ˞ àGȼʶ String ˨ʬȃɈ 4.2.1. ĄƔ Ruby ʬɩϋG7ä #*ß“ýŪ˞ä”Ƶ̕ȠͥƮ ʁß“ȀĻy”Žī ʳ¦̼ř̀ȯRuby RƚʦɩϋXȘɩϋŌ=˨ͯ̕ƍƍ*ºǖEʼʬ̋Ž̕ƑȤʡđ϶ʬEʼ # öǹwĜƩƨƄsÚĜôƭ def full_title(page_title = '') . . . end ˟ ̼ŗȘɩϋͭȔ…ëȈɧʬ`ʡ đǧ§á ̦ʡŽɩϋΣ"/ͭȔEʼʬ`ʡƴRǚʉ϶ʬƊƁ±ɩϋdIJ $ rails console >> 17 + 42 # ÚÙPăƃı => 59 ϠͯʬΣːđǧ§áΝ~Ƶ̕ģ§˪΀úFȒIJȷưƮaàG±ɩϋÓɗǧ§áRƚʦɩϋ 4.2.2. ‹ĭ Ō Web ŷʡȱͭĻ˞ Ƶ͛Șȣύͅʬȁǟ̀ȴĊ"̏ϷʬŠňŗȘBȥ²ćÔδ́ɮ͊ćʬĻ˞  ƴH{đǧ§á\Ј Ļ˞ $ rails console >> "" # ĩ‹ĭ => "" >> "foo" # Ƨĩ‹ĭ => "foo" Ϊ8ȘĻ˞ Ļ϶ώcʡÒƂä" żǧ§áĉșʬȘɞ ̼ʬ͑ˤ̀ȷȪdĻ˞ Ļ϶ώʬ ̀ȷŗȘĻ˞ ȪΓ ƴHΩàGcʡ + äήǦĻ˞ >> "foo" + "bar" => "foobar" # ‹ĭƈÊ "foo" ήǦ "bar" ƒ¦ʬ̀ȷȘĻ˞ "foobar"3 Ý ˋ żĻ˞ ʬȈƁȘιΣʒɚʬÜɧ #{} Ϋ̼Ǭoǵ` 4 3. ƒ4“foo”û“bar”GÑĩʴƒʬ“foobar”û“FUBAR”ʬΈɸͮȼʶ Jargon File @˽“foo”ʬȃ˜ 4. ʊƦ Perl Ƶ PHP ʬ̋ː=öàGLjΪ°̢̞³Ǭo̒y˞äŽīʬ×ώʴŌŷdIJ "foo $bar" 4.2. ‹ĭoÞă - 101 >> first_name = "Michael" => "Michael" >> "#{first_name} Hartl" => "Michael Hartl" # bƖŶ8 # ‹ĭÎ8 ƴH{Lj "Michael" ΃ó×ώ first_nameʈëՅǬ~Ļ˞ "#{first_name} Hartl" ƴH*àGLj Ļ˞ χ΃ó×ώ >> first_name = "Michael" => "Michael" >> last_name = "Hartl" => "Hartl" >> first_name + " " + last_name => "Michael Hartl" >> "#{first_name} #{last_name}" => "Michael Hartl" # ‹ĭƈÊƞPĩ÷ # 2ėĞiĜÎ8 ɩƮȣë̿ΠƁʬ`ʡʴéΣƴpì4cʡǬoʬȈƁđĻ˞ Ϟ±~ ˓Ʌ" " șƒƑ¥ǂ »[‹ĭ ƾÈĻ˞ ȣŭʡʬ Ruby ȈɧȘ putsͯ`“put ess”ƮƞȘ“ƾÈĻ˞ ” >> puts "foo" foo => nil # »[‹ĭ puts ȈɧΩȤ ®`ʡ puts "foo" {LjĻ˞ ƾȦŝŮʈëΨĉ˓oĻ϶ώ——nil đ Ruby Ș ʒɚo̿ˁ“>%χɥȤ”"/̼ȃˣɪë̆ŠňRʵʦ ⇒ nil Bª϶ʬdĺàGʶ—puts ȈɧR̢³đΝ—ʬĻ˞ ë϶±~Ǟ̼˞ \n°̞˨Wʬ print Ȉɧž R >> print "foo" foo=> nil >> print "foo\n" foo => nil # »[‹ĭo puts 2ėõ.ĂĈPÆŘĭ # o puts "foo" õ X®g‹ĭ ʲª@˽ʬdĺχcʡÒƂä żĻ˞ Σ Ruby *ǷǘʡÃƂä żĻ˞ ħĥȁƧ‘ΪˋĻ ˞ ʬǽȷȘ ɂʬ >> 'foo' => "foo" >> 'foo' + 'bar' => "foobar" # X®gI«Ĝ‹ĭ ΣˋȈƁ'ϞȤύͅʬ½¥ Ruby RŌÃƂäĻ˞ Ϋ̼Ǭoǵ` >> '#{foo} bar' => "\#{foo} bar" # X®g‹ĭ ōƇŘÎ8Ó2 102 - Į 4 ī Rails ŌkĜ Ruby ɩƮǧ§áΨĉʬȘÒƂäĻ˞ ĊɘͅcʡÓȅ˷Ε&ʒɚĻ˞dIJ # IJȷÒƂäĻ˞ àGsÃƂä̞sʬƺȤ2̖Ω̞Ϋ̼Ǭoτ%ÃƂäĻ˞ ļđʬƮ&Ș>% ÷ ÃƂäĻ˞ ʬʡġđ4ľHʷʬŗȘĻ϶oÞºñaΝ~ʬĻ˞dIJÓȅ˷đƑĥ˭̃χƑ ʒɚdIJđǞ̼˞\nIJȷȤ ×ώϳͅºñ Óȅ˷cʡÃƂäŗƑˣà >> '\n' => "\\n" # _ÜĻo n ‹ƨ8 ûª϶ʬ # Ļ˞ ɂRuby ͅcʡ ЁĤʬÓȅ˷ȱΕ&Óȅ˷——đÒƂäĻ˞ ̿ͅΠ Óȅ ˷ŗͅcʡÓȅ˷ŌˣÃʬdĺȱͭΪʵ/ĥŒ2XȘIJȷȤƑĥϳͅΕ&ʬĻ˞ŗșƒ—ľ ʬ`ʡ/ >> 'Newlines (\n) and tabs (\t) both use the backslash character \.' => "Newlines (\\n) and tabs (\\t) both use the backslash character \\." ȣëȤ ʁͅɩƮÃÒƂäěȪàG6Ǟcʡɸʼ˾ŭɲʡɥȤ˜ɧàƓŌɘƴHÞ̞ЎЎ ǦÖ——“ɑΥΫ~ Ruby ʤ” 4.2.3. ”Ųoćµ,Ɖ đ Ruby  ›ʭŌͶºǖĻ˞ û nil χȘƴHRđ 4.4.2 ̩@˽ŌͶLJȫś϶ʬƮ&Σ ̦ ƑϯιΣϠͯ Ȫ,ŗʞ͍ŌͶaͅĥʶ 8dĺƼ̞ż˘ŌŌͶʬƯƟ͒͠ ŌͶʬ`ʡͭΈȱƑˣà þŷɯƣdIJ Ļ˞ ŌͶàGþŷ length ΪɯƣΨĉĻ˞ ºñ ʬĻ˞ȁώ >> "foobar".length => 6 # À length ćµ,ŀ‹ĭ ̦ȱͭŚŌͶʬɯƣȘ“Ȉɧ”ȘđΪŌͶł&ʬ™ȁ5 Ļ˞ ΩàGþŷ empty? Ȉɧ >> "foobar".empty? => false >> "".empty? => true ɩƮempty? ȈɧȩřȤϝäΪȘ Ruby ʬ˳łͭȔȈɧʬΨĉoȘũœoÉ true Ƶ falseũœ ođɬːǧ§ʒ¥Ȥʡ >> s = "foobar" >> if s.empty? >> "The string is empty" >> else >> "The string is nonempty" >> end => "The string is nonempty" IJȷšǷƑĥàGcʡ elsifelse + if 5. ƑnjɔȪ˜đ“™ȁ”û“Ȉɧ”ˎù'ϞϬƮ×Ǟđ Ruby Ϊ3̕Șé ɍƙ ƺȤȈɧχȘ™ȁƺȤ™ȁ* χȘȈɧĊ" ›ʭŌͶ 4.2. ‹ĭoÞă - 103 >> if s.nil? >> "The variable is nil" >> elsif s.empty? >> "The string is empty" >> elsif s.include?("foo") >> "The string includes 'foo'" >> end => "The string includes 'foo'" ũœoΩàGcʡ &&û||Ƶû !ϵǵ`˞̀èđ Έcʡ >> x = "foo" => "foo" >> y = "" => "" >> puts "Both strings are empty" if x.empty? && y.empty? => nil >> puts "One of the strings is empty" if x.empty? || y.empty? "One of the strings is empty" => nil >> puts "x is not empty" if !x.empty? "x is not empty" => nil Ċ"đ Ruby  ›χȘŌͶτ% nil *ȘŌͶƺGľ*àGþŷȈɧ$dĺto_s ȈɧěȪà GLjK]ŌͶΕǞƳĻ˞ >> nil.to_s => "" ̀ȷșʈȘ˓Ļ˞ ƴHàGιΣ϶ʬȈɧ ̘chainЈ͟Ϊ ʁ >> nil.empty? NoMethodError: undefined method `empty?' for nil:NilClass >> nil.to_s.empty? # ćµŋ => true ƴHʶ¦nil ŌͶȪΓȌɧþŷ empty? ȈɧXȘ nil.to_s àG Ȥ ʒɚʬȈɧàGɭͤŌͶȘï"˓aƵ̞͛ʘ¦ΪȈɧ >> "foo".nil? => false >> "".nil? => false >> nil.nil? => true ϶ʬEʼ puts "x is not empty" if !x.empty? ɼˁ/ if ƒϗĻʬÝ ˋʡɧ aàG̋Ž ƈÞƈ if ë϶ʬ̿ΠƁ"ʷoȒƼǀ̼ʬͪÜΩȤ Ōŷʬ unless ƒϗĻ*àGΪ%ʡ 104 - Į 4 ī Rails ŌkĜ Ruby >> string = "foobar" >> puts "The string '#{string}' is nonempty." unless string.empty? The string 'foobar' is nonempty. => nil ƴHϳͅɩƮ  nil ŌͶʬʒɚƟϪ/ false ȪΓ'ĤƺȤ Ruby ŌͶľȘā ũœo"“q” ʬƴHàGcʡ !!ͯ`“bang bang”ŌŌͶsɐÕÓǵ`LjŌͶΕǞƳũœo >> !!nil => false Ϫɘ'Ĥ…DƺȤ Ruby ŌͶχȘ“ʷ”oȁĻ 0 *Ș >> !!0 => true 4.2.4. Þă đǧ§áƴHàGvł& home ³`Eʼɴà 3.6û full_title Λ´ȈɧEʼɴà 4.2 ɂł& Ȉɧđǧ§áł&ȈɧȤʁЍʅƴH ̦RđȃIł&ΪόÞȘ"/ɼˁdIJƴHͅł & ê" string_message ʬȈɧǦÖ ÏȁΨĉoՐ4ÏȁȘï"˓ >> def string_message(str = '') >> if str.empty? >> "It's an empty string!" >> else >> "The string is nonempty." >> end >> end => :string_message >> puts string_message("foobar") The string is nonempty. >> puts string_message("") It's an empty string! >> puts string_message It's an empty string! IJȣë úFƺˁàGŁǙłÏȁΪˋƧ‘àGʵʦǖäĊ" def string_message(str = '') ǫe/ÏȁʬЎ͒oÉ˓Ļ˞ ƺGstr ÏȁȘàζʬIJȷǙłŗcʡЎ͒o ɩƮRuby ȈɧʡșƁǙłΨĉoȈɧʬΨĉoȘȣë ͪÜʬ͑ˤ̀ȷ϶Ϊ™ȁʬΨĉoȘ Ļ˞ ʬ †\Șÿ Ր4 str ÏȁȘï"˓đ Ruby Ȉɧ*àGșƁǙłΨĉo ϶ΪȈɧûª϶ʬˠJ >> def string_message(str = '') >> return "It's an empty string!" if str.empty? >> return "The string is nonempty." >> end ˺ƕʬͯ̕à̞RÔʜ…ŃɥƖͅcʡ˟3 returnΪ ̼ȘȈɧʬȣë ̿ΠƁ˥ȤɥȤ returnĻ˞ "The string is nonempty." χR`"ΨĉoΨĉΣġχ± return ʶΈȱȠı 4.2. ‹ĭoÞă - 105 ΩȤ ʁƑύͅȈɧŲƒƕÏȁʬêĻȘ>%đª϶ł&ʬ˟ ȈɧàGLj str ǞƳKƮȤǽ ʬ×ώêdIJ the_function_argumentXȘȈɧʬ`ʡ× >> def string_message(the_function_argument = '') >> if the_function_argument.empty? >> "It's an empty string!" >> else >> "The string is nonempty." >> end >> end => nil >> puts string_message("") It's an empty string! >> puts string_message("foobar") The string is nonempty. 4.2.5. sƫôƭĜſSÞă ϶ƴHȱʞ͍ Eʼɴà 4.2 ʬ full_title Λ´Ȉɧ6 đ…±ɩ͍'ëIJEʼɴà 4.9 ƺˁ 'ĢĉX 4.9Ąş full_title Þă app/helpers/application_helper.rb module ApplicationHelper # öǹwĜƩƨƄsÚĜôƭ def full_title(page_title = '') base_title = "Ruby on Rails Tutorial Sample App" if page_title.empty? base_title else "#{page_title} | #{base_title}" end end end # wÛøãĥĜĄƔ # Þă]ÙeƊ # bƖŶ8 # ¡—ąŨ # ƣ­Ƅs8 # ‹ĭÎ8 Ȉɧł&×ώ΃oũœɭͤɬːǧ§ûĻ˞ Ǭo——˹èđ Έł&/ àGđ̏˚ũŚcʡ ʬΛ´ȈɧΪόΩȤ ʺ͠ʁ——module ApplicationHelper ɏĖ"ƴHǫe/ ˋLjʴƒȈɧ˹˻đ ΈʬȈƁƴHàGcʡ include LjɏĖǬ~…Dʬ˨̋ŽȚιʬ Ruby ːŵȒa̢ͅŧł& ɏ ĖʈëŒșƁՅƂ~˨XȘΛ´ȈɧƺđʬɏĖRʢ Rails "ƴHƂ~̀ȷȘfull_title Ȉɧ ̢³àđƺȤ͉ďcʡ 4.3. ?&ÙÇij{ ̺ʈ Web ŷʡȣ˼χȘġʞĻ˞ X*ϳͅ…Dʬȁǟ˨ėȱʠƳĻ˞ Ȫ̩@˽ 8ŌŽÔ Rails ŷ ʡƑύͅʬ…D Ruby ȁǟ˨ė 6. …ŃΩȤ ĒȈƴHʞ͍τŗȘ Rails ȘƜ%LjΪ8̘˭đ Έʬ Lj URL ȗŏ¦³`͔ full_title Λ´Ȉ ɧàGđ͉ďcʡˠˠΪȘƑȤƮƞʬͦЀƴż͖aGëıı/͍ Σcʡ Rails ŲϳͅŁ/͍ Rails ʬ Φ`Ȭʞ̫Ƭɱ~/͍ RailsƴǨ̯Ϡͯ Obie Fernandez ŽʬThe Rails 4 Way 106 - Į 4 ī Rails ŌkĜ Ruby 4.3.1. ÙĽo8| ȁ˹Ș ˹†ȤʒłϺŵʬyˮª϶ΩɥʡΣȁ˹Σʞ͍ȁ˹Ōʞ͍ýŪȤƑħŬ´4.3.3 ̩* Ȥ´4ʞ͍ Rails ʬȁǟɏėdIJ 2.3.3 ̩ʡ¦ʬ has_many ƒ̘11.1.3 ̩Rsͩ˺@˽ ʲªƴHŨ˾̪/ƑĥȒϞʞ͍Ļ˞ BĻ˞ Σɶ¦ȁ˹àGB split ȈɧŽĶ >> "foo bar baz".split => ["foo", "bar", "baz"] # À‹ĭÂF¶ç :ĶĜÙĽ ΰǵ`ƒ¦ʬ̀ȷȘ ȤĻ˞ ʬȁ˹Ў͒Ƨ‘split đ˓ɅġLjĻ˞ ǐšƳȁ˹Σ *àGđ•(K]ĒȈǐš >> "fooxbarxbazx".split('x') => ["foo", "bar", "baz"] ûħĥȁ̋ːͪ͏ʬ+ƫ ɂRuby ȁ˹ʬ˯Ƃ*BϲŽĶĊɘȁ˹˟ yˮʬ˯ƂȘ 0˟3y ˮʬ˯ƂȘ 1fɘ˨Ǩ >> a = [42, 8, 17] => [42, 8, 17] >> a[0] => 42 >> a[1] => 8 >> a[2] => 17 >> a[-1] => 17 # Ruby 3ėÞÄgŖaÙĽ:Ķ # ķ®ƅe)âųÙ ƴHʶ¦Ruby cʡȈǖä̰Õȁ˹ʬyˮϪ/Ȉǖä'ĤRuby Ω" 8˾ŭϳ̰ͅÕʬyˮǫe /¥ê 7 >> a => [42, 8, 17] >> a.first => 42 >> a.second => 8 >> a.last => 17 >> a.last == a[-1] => true # dâĠ a Ĝ8â! # ė == ĭg”Ā ȣë ̼ʡ¦/ʴˠɟΚǵ`˞ ==Ruby û…Dͪ͏ ɂΩǫe/ !=ˠˠ…Dǵ`˞ >> x = a.length => 3 >> x == 3 => true # o‹ĭõÙĽe)q© length Þă 7. ΪɛEʼcʡʬ second ȈɧȘ Ruby ł&ʬ̖Ș Rails ɳ±ʬđΪόàGcʡΪȈɧȘĊ"Rails ǧ§áR̢ ³±Ι Rails Ō Ruby ʬǁŞ 4.3. ?&ÙÇij{ - 107 >> x == 1 => false >> x != 1 => true >> x >= 1 => true >> x < 1 => false Ϫ/ lengthΰEʼʬ˟ ̼'Ĥȁ˹ΩàGþŷ ˭…DȈɧ >> a => [42, 8, 17] >> a.empty? => false >> a.include?(42) => true >> a.sort => [8, 17, 42] >> a.reverse => [17, 8, 42] >> a.shuffle => [17, 42, 8] >> a => [42, 8, 17] ɩƮ϶ʬȈɧχɥȤkǹ a ʬoIJȷƬkǹȁ˹ʬoͅcʡʴŷʬ“ʀƅ”bangȈɧ'ƺGΪ %ßȘĊ"ΪόʬƯæä˾ŭχͯ`“bang” >> a => [42, 8, 17] >> a.sort! => [8, 17, 42] >> a => [8, 17, 42] ΩàGcʡ push Ȉɧìȁ˹ɳ±yˮƵ̕cʡˠJʬ << ǵ`˞ >> a.push(6) # À 6 PMÙĽĿ™ => [42, 8, 17, 6] >> a << 7 # À 7 PMÙĽĿ™ => [42, 8, 17, 6, 7] >> a << "foo" << "bar" # ŋÓ2 => [42, 8, 17, 6, 7, "foo", "bar"] ȣë úFͭȔàGLjɳ±ǵ` đ Έcʡ *ͭȔRuby vƑĥ…Dͪ͏ȁ˹àGºñé ˨ėʬȁǟȪdºñȂȁûĻ˞  ª϶ʡ split LjĻ˞ ǐšƳĻ˞ ƴHΩàGcʡ join ȈɧΫ̼ʴÓʬǵ` >> a => [42, 8, 17, 7, "foo", "bar"] >> a.join # ĂçƈÊĭ => "428177foobar" 108 - Į 4 ī Rails ŌkĜ Ruby >> a.join(', ') => "42, 8, 17, 7, foo, bar" # ƈÊĭâ Ƌgoĩ÷ ûȁ˹Ȥʁ˨WʬȘoęrangecʡ to_a ȈɧLjľΕǞƳȁ˹Ƶ͛Ƞıʞ͍ >> 0..9 => 0..9 >> 0..9.to_a # ƚto_a w 9 Űė NoMethodError: undefined method `to_a' for 9:Fixnum >> (0..9).to_a # Űė to_a śėÄgT08| => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ̺ʈ 0..9 ȘȤǽʬoęΣ϶˟3̿ΠƁõ͡ƴHͱʡȈɧȒͅ±ǖä oę˾ŭʡȱ̰Õȁ˹ʬ ˹yˮ >> a = %w[foo bar baz quux] => ["foo", "bar", "baz", "quux"] >> a[0..2] => ["foo", "bar", "baz"] # %w I« :Ķ‹ĭĜÙĽ Ȥʒ¥ȤʡʬLJť oęʬ̀ȯocʡ -1 Ȓʡʺοȁ˹ʬϙźŗ̞BΈĶoŽĶ ʳ̰Õ¦ȣë  yˮ >> a = (0..9).to_a => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >> a[2..(a.length-1)] => [2, 3, 4, 5, 6, 7, 8, 9] >> a[2..-1] => [2, 3, 4, 5, 6, 7, 8, 9] # ã­3ėÙĽĜƜª # –¿Ÿķ®3ė -1 oę*àGcʡĻɝ >> ('a'..'e').to_a => ["a", "b", "c", "d", "e"] 4.3.2. z ȁ˹ûoęàGþŷʬȈɧȤƑĥχàGΎʹ ĖblockΪȘ Ruby ȣƆħ*Șȣϯʞ͍ʬ°̞ >> (1..5).each { |i| puts 2 * i } 2 4 6 8 10 => 1..5 ΪɛEʼđoę (1..5) ͱʡ each ȈɧʈëÐLj { |i| puts 2 * i } ΪĖŚ each Ȉɧ|i| Οʬ ˙˷đ Ruby ʡȱł&Ė×ώÞȤΪȈɧƼʺοIJ]ġʞë϶ΎʹʬĖȪdoęʬ each ȈɧR ġʞë϶ʬĖĖȤ ȪĒ×ώ ieach RLjoęʬçoSΫĖʈëǀ̼…ʬEʼ ̪ǖäȘ̿ˁĖʬ ˋȈƁϪɘ'ĤΩȤÝ ˋȈƁ 4.3. ?&ÙÇij{ - 109 >> (1..5).each do |i| ?> puts 2 * i >> end 2 4 6 8 10 => 1..5 ĖʬŠňàGĥ4 ̼̖˾ŭĥ4 ̼Ȫ,ρʉ ŭʡʬ˳łƈĖÞȤ ̼ˣÃʬEʼȒcʡ ̪ǖäƊƁ ƈĖȘ ̼ƑϙʬEʼƵ̕Ȥĥ̼Ȓcʡ do..end ƊƁ >> (1..5).each do |number| ?> puts 2 * number >> puts '-' >> end 2 4 6 8 10 => 1..5 ϶ʬEʼʡ number EȢ/ iƴƬõ͡aʬȘ×ώêàGcʡK]o ϪϵaŨ˾Ȥ/ 8̋ːʺ͠ïžŌĖʬʞ͍ȘɥȤǠƏʬaͅsʬȘĥʶʶĥ/ŗR+ƫΪˋʡ ɧ8 ųı=˨ǴϙBŃdƇ˶— ̦Ɵ϶Ș 8dĺ…•ʡ¦/ map Ȉɧ >> 3.times { puts "Betelgeuse!" } # 3.times kŸĜzĂçbƖ "Betelgeuse!" "Betelgeuse!" "Betelgeuse!" => 3 >> (1..5).map { |i| i**2 } # ** řĥ¥ƃı => [1, 4, 9, 16, 25] >> %w[a b c] # BŬ %w ėîI«:Ķ‹ĭĜÙĽ => ["a", "b", "c"] >> %w[a b c].map { |char| char.upcase } => ["A", "B", "C"] >> %w[A B C].map { |char| char.downcase } => ["a", "b", "c"] àGʶ—map ȈɧΨĉʬȘđȁ˹Ƶoęɞyˮǀ̼ĖEʼ냦ʬ̀ȷđȣëúF map ë϶ʬĖđĖ×ώͱʡ ȈɧΪˋǵ`˾ŭcʡˣŽƊƁ 8. ĖȘϜºclosureʺοΪ ʁŌ΂ɱ̋ː=öà̞RȤ8Ŭ´ϜºȘ ˋ¾ê™ȁ…Ϥū/ 8ȁǟ 110 - Į 4 ī Rails ŌkĜ Ruby >> %w[A B C].map { |char| char.downcase } => ["a", "b", "c"] >> %w[A B C].map(&:downcase) => ["a", "b", "c"] ˣŽƊƁʶΈȱȤʁwĭƠ…ʡ¦/˞ä4.3.3 ̩R@˽ΪˋŽɧɟΚȤ΋ ŽĶȘʢ Rails ǁŞŃʜʬX=Hĩąɑ/ʜđŨ˾ϱƳ¦ Ruby ɃƕEʼ ȣëŒʶ cʡĖʬdĺƴHʶ Eʼɴà 4.4 ʬ ɭͤʡd test "should get home" do get :home assert_response :success assert_select "title", "Ruby on Rails Tutorial Sample App" end ʜđϳͅʞ͍˺̩…Ńƴ*ƲB do ƒϗĻàGʶ—ɭͤʬ#\…ŃŗȘĖtest ȈɧʬÏ ȁȘ Ļ˞ ɭͤʬǪΰû ĖΦ̼ɭͤ˹IȒRǀ̼ĖʬŠň ʜđƴHȱšȵ ƴđ 1.5.4 ̩ʠƳϬȬ3˴ęêȒcʡʬτ̼ Ruby Eʼ ('a'..'z').to_a.shuffle[0..7].join ƴH əəš͍ >> ('a'..'z').to_a # Ę<ƑŕۋþĽ¶ĜÙĽ => ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] >> ('a'..'z').to_a.shuffle # »ÙĽ => ["c", "g", "l", "k", "h", "z", "s", "i", "n", "d", "y", "u", "t", "j", "q", "b", "r", "o", "f", "e", "w", "v", "m", "a", "x", "p"] >> ('a'..'z').to_a.shuffle[0..7] # aDO 8 :Ķ => ["f", "w", "i", "a", "h", "p", "c", "x"] >> ('a'..'z').to_a.shuffle[0..7].join # ÀaDĜ:Ķh¦¶‹ĭ => "mznpybuj" 4.3.3. p¢oĭg ýŪHashȪͽŗȘȁ˹ÞΣľʬ˯ƂŚϨ4Þ̞cʡȁĻŃϥđ 8ͪ͏ʒ¥Ș PerlĊ"ΪÍĊLjýŪßs“ƒ̘ȁ˹”ýŪʬ˯ƂƵ̕ß“ϗ”•(àGcʡK]ŌͶdIJà GcʡĻ˞ ƈϗ >> user = {} # {} â ĩp¢ => {} >> user["first_name"] = "Michael" # ƛ "first_name"8 "Michael" => "Michael" >> user["last_name"] = "Hartl" # ƛ "last_name"8 "Hartl" => "Hartl" >> user["first_name"] # Ŗa:ĶĜÞ­oÙĽij- => "Michael" >> user # p¢Ĝ‹ƨƖ°­ => {"last_name"=>"Hartl", "first_name"=>"Michael"} 4.3. ?&ÙÇij{ - 111 ýŪιΣ Ō̪ǖäºñ 8ϗoŌʬƊƁ̿ˁIJȷÞȤ Ō̪ǖä̖ɥȤϗoŌ{}ŗȘ ˓ý ŪɩƮýŪʬ̪ǖäûĖʬ̪ǖäȘ ɍƙȘʬΪà̞R͔aČƩýŪ̺ʈûȁ˹ ˨WX3̕ÊȤ Ƒύͅʬ½¥ ýŪʬyˮɥȤʒłʬϺŵ9 IJȷϺŵƑύͅʬͦŗͅcʡȁ ˹ ιΣȈǖäʬƊƁɞɐł& yˮʬȈƁĩǾǠcʡ ⇒ šϮʬϗoŌΪˋĻ϶ώƊƁł&ýŪͅˣɪ ƒĥ >> user = { "first_name" => "Michael", "last_name" => "Hartl" } => {"last_name"=>"Hartl", "first_name"=>"Michael"} đ϶ʬEʼƴʡ¦/  Ruby Üɧ˳łđŤ̪ǖäë϶ûã̪ǖäª϶±~/ ˓ɅΣǧ§ áRƚʦΪ8˓Ʌͅϝƴ">%Ϊ8˓ɅȘ˳łhƳʬƵ͛ȘȺ Ruby ̋ːħʐąɑΪˋƊƁ ʈë˳łŗ:ʠ/ ʲª"ɖýŪʬϗχcʡĻ˞ đ Rails ʡ“˞ä”SymbolƈϗƑŭ͆˞äʶΈȱȤʁwvĻ˞ ÞΣɥȤºñđ ŌƂä̖Șđª϶± ädIJ:name ŗȘ ˞äaàGLj˞äʶ ƳɥȤ˳ȯʬĻ˞ 10 >> "name".split('') => ["n", "a", "m", "e"] >> :name.split('') NoMethodError: undefined method `split' for :name:Symbol >> "foobar".reverse => "raboof" >> :foobar.reverse NoMethodError: undefined method `reverse' for :foobar:Symbol ˞äȘ Ruby ʒȤʬȁǟ˨ė…Dͪ͏ƑŒʡ¦¡ʶΈȱƯ͋ƑĭƠΣ Rails ˾ŭʡ¦ƺGaƑƘ ŗR+ƫ˞äûĻ˞ éŲȘƺȤĻ˞χ̞đ˞äcʡ >> :foo-bar NameError: undefined local variable or method `bar' for main:Object >> :2foo SyntaxError ÞͅGĻɝŽī…ëχcʡÃ͢ŭʡʬĻ˞ŗɥ2 ʡ˞äƈϗƴHàGǚʉIJʬȈƁł&  user ýŪ >> user = { :name => "Michael Hartl", :email => "michael@example.com" } => {:name=>"Michael Hartl", :email=>"michael@example.com"} >> user[:name] # Ŗa :name ”©Ĝ8 => "Michael Hartl" >> user[:password] # ŖaéĜƛ”©Ĝ8 => nil B϶ʬdĺàGʶ—ýŪɥȤł&ʬϗŌŷʬoȘ nil 9. đ Ruby 1.9 ÑGëʬʏȪ…ŃRǚʉyˮΝ~ȒʬϺŵiļýŪΣf΄ʒłʬϺŵșʈȘȔȝʬ 10. ɥȤ˳ȯʬıġȘ˞äƑňȕΫ̼ɟΚĻ˞ ͅǚʉĻɝ  ʬɟΚ̖˞äÞϳɟΚ ɐΪŗcƒ˞äƳ" ýŪϗʬȣbζǕ 112 - Į 4 ī Rails ŌkĜ Ruby Ċ"˞äƈϗʬƧ‘ĩȚξ/Ruby 1.9 ů̟ŗ"Ϊˋʡɧł&/ ˋȇÜɧ >> h1 = { :name => "Michael Hartl", :email => "michael@example.com" } => {:name=>"Michael Hartl", :email=>"michael@example.com"} >> h2 = { name: "Michael Hartl", email: "michael@example.com" } => {:name=>"Michael Hartl", :email=>"michael@example.com"} >> h1 == h2 => true ˟3ÜɧLj“˞ä ⇒”×Ƴ/“ϗʬêĻ:”ƊƁ { name: "Michael Hartl", email: "michael@example.com" } ΪˋƊƁȠıĒɦ͂/…Dͪ͏dIJ JavaScriptýŪʬ̿ˁȈƁđ Rails ˂½*ΊȱΊÖɑΥΪ ˋȈƁʜđχđcʡƺGa̞͠ͅ¥ľHàȘȇÜɧȤʁ͔=ČƩĊ" :name ȪΓȘ ˋȁǟ˨ ė˞äX name: ÊɥȤƮ&ΣđýŪĻ϶ώ:name ⇒ û name: `ʡ ɂĊɘ{ :name ⇒ "Michael Hartl" } û { name: "Michael Hartl" } ȘˠǽʬIJȷ̿ͅˁ˞äÞ̞cʡ :nameäđª ϶ ýŪyˮʬoàGȘK]ŌͶʟ̣ȘÝ ýŪIJEʼɴà 4.10 ƺˁ 'ĢĉX 4.10†p¢ >> params = {} #  j paramsparameters ĜİĦĜp¢ => {} >> params[:user] = { name: "Michael Hartl", email: "mhartl@example.com" } => {:name=>"Michael Hartl", :email=>"mhartl@example.com"} >> params => {:user=>{:name=>"Michael Hartl", :email=>"mhartl@example.com"}} >> params[:user][:email] => "mhartl@example.com" Rails ħώcʡΪˋýŪȤýŪʬƊƁƵˎ"“šįýŪ”ƴHB 7.3 ̩ΈRǦ͎¦ ȁ˹ûoę ɂýŪ*̞þŷ each ȈɧdIJ ê" flash ʬýŪľʬϗȘ£ȆȰ I:success û :danger >> flash = { success: "It worked!", danger: "It failed." } => {:success=>"It worked!", :danger=>"It failed."} >> flash.each do |key, value| ?> puts "Key #{key.inspect} has value #{value.inspect}" >> end Key :success has value "It worked!" Key :danger has value "It failed." ɩƮȁ˹ʬ each Ȉɧë϶ʬĖÞȤ ×ώ̖ýŪʬ each Ȉɧë϶ʬĖǦÖ×ώš¥̿ˁϗû ŌŷʬoƺGýŪʬ each ȈɧɞɐξËχRG ϗoŌ"ÃYΫ̼ ΪɛEʼʡ¦/ƑȤʡʬ inspect ȈɧΨĉ́ͱʡŌͶʬĻ˞ Ļ϶ώ̿ʜƊƁ >> puts (1..5).to_a 1 2 3 4 # À8|żÆ¶ÙĽ 4.3. ?&ÙÇij{ - 113 5 >> puts (1..5).to_a.inspect # ƁDÙĽĜ‹ƨƖ°­ [1, 2, 3, 4, 5] >> puts :name, :name.inspect name :name >> puts "It worked!", "It worked!".inspect It worked! "It worked!" Ϻgͭ Ċ"cʡ inspect ƾÈŌͶʬȈƁ˾ŭcʡ"ɘΩȤ ϚʬƘǠȈƁp Ȉɧ 11 >> p :name :name # į+ 'puts :name.inspect' 4.3.4. ƕĊ®; CSS Ĝ'Ģ ʜđƴHͅύȇ͒͠ Eʼɴà 4.1 đũŚƂ~śÙɂƁ̿ʬEʼ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> ƴHʜđěȪàGʞ͍Ϊ̼Eʼ/đ 4.1 ̩ˣÃǫ¦ΣRails ł&/ ʒɚʬ™ȁʡȱƂ~ɂƁ̿ ϶ʬEʼ stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true ŗȘŌΪ™ȁʬͱʡΣΩȤ•ĭƠʬĒȈ˟ ǖäÿÎ/ đ Ruby ǖäȘàGʵʦʬ ƺG϶ˋŽɧȘˠJʬ # ŰėEÙàe)ğěÄg stylesheet_link_tag('application', media: 'all', 'data-turbolinks-track' => true) stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true ˟3media φšșʈȘ ýŪXȘƜ%ɥʡ̪ǖä ͱʡ™ȁȒIJȷýŪȘȣë ÏȁàGʵ ʦ̪ǖäƺG϶ˋŽɧȘˠJʬ # ˆðæk ]Ùâp¢e)ğěŔÄg stylesheet_link_tag 'application', { media: 'all', 'data-turbolinks-track' => true } stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true ΩȤ">% data-turbolinks-track ΪϗoŌcʡȏÜɧ IJȷcʡȇÜɧŽƳ data-turbolinks-track: true ȘȌǽʬĊ"…ȤήĻ˞4.3.3 ̩ͭΣ˞ä̞cʡήĻ˞ƺGÞ̞cʡȏÜɧŽƳ 11. …ŃȤ8˺ƔŦ¥p ΨĉƾÈʬŌͶ̖ puts Ķ˼Ψĉ nilƯʹͯ̕ Katarzyna Siwek Ǚ—Ϊ ʁ 114 - Į 4 ī Rails ŌkĜ Ruby 'data-turbolinks-track' => true ȣë">%Ǟ/ ̼ Ruby Ω̞ɗˀ͍ȵ stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true Ċ"đΪˋƧ‘Ruby ƒƕȤɥȤǞ̼12 ƴ'ƺGLjEʼŽƳ̼Șͅi͟ɞ̼EʼΉΣ 80  Ļ˞13 ƺG϶ΪɛEʼ stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true ͱʡ/ stylesheet_link_tag ™ȁŲS~Ïȁ ȘĻ˞ ǙȔɂƁ̿ʬΐƏ Ý ȘýŪ ºñyˮ˟ ǙȔĹ@˨ė˟3óʡ Rails 4.0 ɳ±ʬ Turbolink °̞Ċ"cʡʬȘ <%= %>™ȁʬǀ̼̀ȷRιΣ ERb Ǭ~ɏȲIJȷđɮ͊ćȼʶ̏ϷʬɸʼRʶ¦Ƃ~ɂƁ̿ƺʡʬ HTMLIJEʼɴà 4.11 ƺˁaà̞Rđ CSS ʬȃIêëʶ¦ЁĤʬĻ˞dIJ ?body=1ΪȘ Rails ± ~ʬˀikǹ CSS ëɮ͊ćRύȇ±Ι 'ĢĉX 4.11®; CSS Ĝ'ĢĖ¶Ĝ HTML IJȷđɮ͊ćƾŽ http://localhost:3000/assets/application.css ȼʶ CSS ʬͦRÔʜȘΪȃIȘ˓ʬX Ȥ 8ɩϋ˟ 5 ˜R@˽IJ]ɳ±ɂƁ 4.4. Ruby ij ƴH'ªͭΣRuby ʬ ›χȘŌͶȪ̩ƴH̢ͅŧł& 8ŌͶRuby û…D϶ìŌͶʬͪ͏ ɂcʡ˨ȱ˹˻ȈɧʈëŃd»˨ żŌͶIJȷaŸǦ͎“϶ìŌͶ̋ː”Object-Oriented Programmingˣˎ OOPΪ8òΈȱχWĨ, ̦τƴHȱʶ 8Ńdð 4.4.1. ïƎÞă ƴHʶΣƑĥcʡ˨¡Ķ»ŌͶʬdĺΣΩɥ̢ŧ³ƻsΣdIJƴHcʡÒƂä¡Ķ» Ļ˞ ÒƂäȘĻ˞ ʬĻ϶ȴλȈɧ >> s = "foobar" => "foobar" >> s.class => String # 3ė^®g‹ƨïƎÞă ƴHʶ¦Ļ˞ àGþŷ class ȈɧΨĉoȘĻ˞ ƺşʬ˨ 12. Ǟ̼˞đ ̼ʬ̀řġŽĶȇʬ ̼đEʼǞ̼˞ʡ \n ̿ˁ 13. ȁȁR͔aÔʧʬƺGƑĥȃȪ̋Μćχǫe/ ͉͋Ⱦ͠dIJIJȷŒʶ ď 1.5 ʬͦRÔʜãΟȤ Ȱ ˺˷ľàGŬ´aLj ̼Eʼǧ§đ 80 Ļ˞GŠ5˝ IDE Ў͒RșˁΪȰ˙˷IJȷcʡ TextMateàGđIJ̱à Dž¦Ϊ°̞ View > Wrap Column > 78đ Sublime Text Ș View > Ruler > 78Ƶ View > Ruler > 80 4.4. Ruby ij - 115 Ϫ/cʡĻ϶ȴλȈɧ'ĤƴHΩàGcʡˠJʬ“†êȴλȈɧ”named constructorÉđ˨êͱʡ new Ȉɧ 14 >> s = String.new("foobar") => "foobar" >> s.class => String >> s == "foobar" => true # ‹ĭĜ@jïƎÞă ΪɛEʼcʡʬ†êȴλȈɧûĻ϶ȴλȈɧȘˠJʬÞȘȠ̞̿ʜƴHʬƮď ȁ˹ûĻ˞ ˨W >> a = Array.new([1, 3, 2]) => [1, 3, 2] ΣýŪŗȤʁé/ȁ˹ʬȴλȈɧ Array.new àǦÖ àζʬÏȁǙȔȁ˹ʬ¡ĶoHash.new à ǦÖ ÏȁǙȔyˮʬЎ͒oŗȘƈϗļđȒΨĉʬo >> h = Hash.new => {} >> h[:foo] => nil >> h = Hash.new(0) => {} >> h[:foo] => 0 # ŨvŖa ŒwĜƛ :foo ”©Ĝ8 # Ţ ŒwĜƛƄs 0 Ŋ â nil đ˨ͱʡʬȈɧIJȪdʬ newß“˨Ȉɧ”class methodđ˨ͱʡ new Ȉɧƒ¦ʬ̀ȷȘΪ ˨ʬ ŌͶ*ßsΪ˨ʬ“Ńd”instanceđŃdͱʡʬȈɧdIJ lengthß“ŃdȈ ɧ”instance method 4.4.2. ijĜł¾ Ľ+˨Ȓʞɴ˨ʬ̄džƒ˭RƑȤʡƴHàGcʡ superclass Ȉɧ >> s = String.new("foobar") => "foobar" >> s.class # ó½ s ¹œĜij => String >> s.class.superclass # ó½ String ĜĐij => Object >> s.class.superclass.superclass # Ruby 1.9 3ė BasicObject 2}ij => BasicObject >> s.class.superclass.superclass.superclass => nil Ϊ̄džƒ˭IJď 4.1 ƺˁàGʶ¦String ʬʌ˨Ș ObjectObject ʬʌ˨Ș BasicObjectXȘ BasicObject ŗɥȤʌ˨/Ϊɂʬƒ˭Ōɞ Ruby ŌͶχεʡ Þͅđ˨ʬ̄džƒ˭ƍĥΆ•śŗRÔ 14. Ψĉoà̞ʢ4 Ruby ʏȪʬé̖ȤƺéΪdĺq͝acʡʬȘ Ruby 1.9.3 ƵGʏȪ 116 - Į 4 ī Rails ŌkĜ Ruby ʜ Ruby ʬɞ˨ȣ˼χ̄dž̢ BasicObject̖ľȪΓɥȤʌ˨ΪŗȘ“Ruby  ›ʭŌͶ”LJȫś϶ ʬƮ& v 4.1String ijĜł¾>ĵ ͅƬȠɱ~Ēʞ͍˨ȣıʬȈɧȘ̢ŧ³ƻ̋Ž ˨ƴHȱł& ê" Word ʬ˨…Ȥ ê" palindrome? ȈɧIJȷÃ͢ϺͯûÓͯχ ɂŗΨĉ true >> class Word >> def palindrome?(string) >> string == string.reverse >> end >> end => :palindrome? ƴHàGǚʉ϶ʬȈƁcʡΪ˨ >> w = Word.new => # >> w.palindrome?("foobar") => false >> w.palindrome?("level") => true # I« Word ”Ų IJȷa͋ƒΪdĺȤʁħЀősƑıƴʬʲʬΠ¦/ł& ȇ˨àȘÞ ż ǦÖ Ļ˞ `"ÏȁʬȈɧΪ%sƑÛƠȍʈÃ͢ȘĻ˞ ͔ Word ̄dž String ŗ̼/IJEʼɴà 4.12 ƺ ˁaͅγ—ǧ§áʈëŒđǧ§áΝ~ڎEʼΪɂƼ̞Lj'ªʬ Word ł&ɴϪǢ 'ĢĉX 4.12wËNf Word ij >> class Word < String # Word ł¾Ő String >> # ˆð‹ĭo_żkĞį˜Ƅs true >> def palindrome? >> self == self.reverse # self 'řƆ ‹ĭêŻ >> end >> end => nil 4.4. Ruby ij - 117 …Word < String đ Ruby ̿ˁ̄dž3.2 ̩ˣ@ΣΪɂϪ/ł& palindrome? Ȉɧ'ĤWord Ωǔ ȤƺȤĻ˞ ǔȤʬȈɧ >> s = Word.new("level") => "level" >> s.palindrome? => true >> s.length => 5 # I« Word ‘4J‰8 "level" # Word ‘4e)q© palindrome? Þă # Word ‘4ƅł¾äƌ‹ĭĜ¹çÞă Word ̄dž̢ StringƴHàGđǧ§áȼʶ˨ʬ̄džƒ˭ >> s.class => Word >> s.class.superclass => String >> s.class.superclass.superclass => Object Ϊ̄džƒ˭IJď 4.2 ƺˁ v 4.2'ĢĉX 4.12 Ĝ Word ijƧAŇijĜł¾>ĵ ɩƮđEʼɴà 4.12 ɉȼÃ͢ûÃ͢ʬÓΕȘïʴéȒͅđ Word ˨ƂʡΪÃ͢đ Ruby cʡ self ƒϗĻ15 Ƃʡ đ Word ˨self E̿ʬŗȘŌͶȪΓƺGƴHàGcʡ self == self.reverse ȱɉȼÃ͢Șï"“ĉȃ”…Ńđ˨ͱʡȈɧƵ͞ϝşƟȒàGʡ self.΃oȒ̼ƺG*à GŽƳ self == reverse 15. ƒ4 Ruby ˨û self ƒϗĻͮϠͯ RailsTips ʬClass and Instance Variables in Ruby ȃ 118 - Į 4 ī Rails ŌkĜ Ruby 4.4.3. 6ÕAŇĜij ̺ʈ̄džȘƑƆħʬ°̞Σđ£ȆĉȃΪdĺIJȷ̞Lj palindrome? ±~ String ˨ŗȠı/ ΪɂϪ/…DȈɧĤƴHàGđĻ˞ Ļ϶ώͱʡ palindrome? ȈɧʜđƴHΩ̞ʳǦͱʡ >> "level".palindrome? NoMethodError: undefined method `palindrome?' for "level":String ȤʁF=ƨ͚ʬȘRuby x͛aΪ%sRuby ʬ˨àǴƾŽΫ̼kǹx͛vƴHΪɂʬȚι=ɳ± 8Ȉɧ >> class String >> # ˆð‹ĭo_żkĞį˜Ƅs true >> def palindrome? >> self == self.reverse >> end >> end => nil >> "deified".palindrome? => true ƴʺοÿ Ƞʐ Ruby x͛ìŠ̐ʬ˨ɳ±ȈɧƵ "deified" Șĉȃ kǹŠ̐ʬ˨ȘƑƆħʬ°̞Σ°̞ƆħƮøʹͺK*ħIJȷɥȤƑıʬʞʢìŠ̐ʬ˨ɳ± ȈɧȘıʬ+ƫRails ̢ʈȤƑıʬʞʢdIJđ Web ŷʡƴH˾ŭͅς}×ώʬoȘ˓ʪ blankʬvʡƹê'˨ʬŗŷͨȘ˓ɅƵ˓ʪƺG Rails " Ruby ɳ±/  blank? ȈɧRails ǧ §áR̢³±Ι Rails ɳ±ʬ°̞϶ʶ•dĺđ irb àG >> "".blank? => true >> " ".empty? => false >> " ".blank? => true >> nil.blank? => true àGʶ— ºñ˓ɅʬĻ˞ Ș˓ʬemptyÊȘ˓ʪʬblankῼɩƮnil *Ș˓ʪʬ Ċ" nil ȘĻ˞ ƺG϶ʬEʼͭȔ/ Rails …ŃȘLj blank? ɳ±¦ String ʬě˨ Object ʬ8.4 ̩RŒ@˽ 8 Rails ǁŞ Ruby ˨ʬdĺ 4.4.4. ËNrij ͓͜˨û̄džȒaà̞͋ƒWȡʴ͠ϖƴH'ª͆ΣđϴƛϷ϶ǧ§ćEʼɴà 3.18 class StaticPagesController < ApplicationController def home end def help end 4.4. Ruby ij - 119 def about end end aʜđàGʞ͍̣ŒȤʁ̞ʞ͍Ϊ8EʼʬƮƞ/ StaticPagesController Ș ˨̄dž̢ ApplicationController…ȤȈɧš¥Ș homehelp û aboutĊ" Rails ǧ§áR±ΙȪĒʬ Rails ʛ ĝƺGƴHàGđǧ§á ż ǧ§ćȼʶ ľʬ̄džƒ˭ 16 >> controller = StaticPagesController.new => # >> controller.class => StaticPagesController >> controller.class.superclass => ApplicationController >> controller.class.superclass.superclass => ActionController::Base >> controller.class.superclass.superclass.superclass => ActionController::Metal >> controller.class.superclass.superclass.superclass.superclass => AbstractController::Base >> controller.class.superclass.superclass.superclass.superclass.superclass => Object Ϊ̄džƒ˭IJď 4.3 ƺˁ ƴHΩàGđǧ§áͱʡǧ§ćʬ³`³`…ŃŗȘȈɧ >> controller.home => nil home ³`ʬΨĉo" nilĊ"ľȘ˓ʬ ɩƮ³`ɥȤΨĉoƵ̣ŒɥΨĉʷɗϳͅʬoIJƴHđ˟ 3 ˜ʶ¦ʬhome ³`ʬʲʬȘɷȻ̏ Ϸ̖ȘΨĉ oXȘƴ͘ƒɥđK]ĒȈͱʡΣ StaticPagesController.new¦ŸƜ%ĉ2÷ ÍĊđ4Rails Șʡ Ruby ̋ŽʬX Rails Ș RubyȤ8 Rails ˨ŗvȚιʬ Ruby ˨ ɂΣ*Ȥ8 žƒʯ4 Rails ʬƆħ°̞Rails ȘÃʖʬ ϚĽϝŷͨû Ruby šŽĽ+ûʞ͍ 16. aɥƖͅʺο̄džƒ˭ɞ˨ʬ`ʡƴ*ʺοľHχȘů>%ʬ̖ƴB 2005 űŗŽĶcʡ Ruby on Rails /Ϊ à̞ƮøʹGϝЀʬ  ˟ ƴȘŹȽ ˟3ϳͅʺοƺȤŠφʺ͠*̞Ƴ"ʊ˸ʬ Rails ŽÔ̕ƴH ƈʈχŪȦȘ˟3ʁ 120 - Į 4 ī Rails ŌkĜ Ruby v 4.3Ʀ³ƩƨËNrĜijł¾>ĵ 4.4.5. ė¸ij ƴH̢ͅŧł& ˨̀ȯŌ Ruby ʬ@˽Ϊ˨ê" UserʲʬȘŃʜ ˟ 6 ˜ʡ¦ʬʡƹɏė ¦ʲª"ɖƴHχđǧ§áł&˨ΪɂƑƘǠX*ȤʁʍʜđƴHͅđŷʡʬɄʲƉ ż ê" example_user.rb ʬȃIʈëŽ~Eʼɴà 4.13 ʬŠň 'ĢĉX 4.13 User ij example_user.rb class User attr_accessor :name, :email def initialize(attributes = {}) @name = attributes[:name] @email = attributes[:email] end def formatted_email 4.4. Ruby ij - 121 "#{@name} <#{@email}>" end end ΪɛEʼȤƑĥĒȈͭͅȔƴH əəȱ{ʶ϶Ϊ̼ attr_accessor :name, :email Ϊ̼Eʼ"ʡƹʬêĻûʣĺυIĒĔ ż“şƟ͞ϝć”attribute accessors*ŗȘł&/“̰ÕȈ ɧ”getterû“͝łȈɧ”setterʡȱÕĉû΃o @name û @email Ńd×ώ2.2.2 ̩û 3.6 ̩ˣ@ Σđ Rails Ńd×ώʬƮ&đ4ľH̢³đ͉ďàʡ̖ιŭŃd×ώʬ`ʡȘđ Ruby ˨ éʬȈɧ'ϞSθoˑëRȠͩ˺Ē@˽Ϊ ʁŃd×ώơȘG @ ˞äŽīIJȷȨł&o" nil ˟ Ȉɧinitializeđ Ruby ȤʒɚʬƮ& ǀ̼ User.new ȒRͱʡΪȈɧΪ initialize Ȉ ɧǦÖ Ïȁattributes def initialize(attributes = {}) @name = attributes[:name] @email = attributes[:email] end attributes ÏȁʬЎ͒oȘ ˓ýŪƺGƴHàGł& ɥȤêĻƵɥȤʣĺυIĒĔʬʡƹĉ Ƭ  4.3.3 ̩ʬŠňIJȷϗļđŗΨĉ nilƺGIJȷɥł& :name ϗattributes[:name] RΨĉ nilattributes[:email] *Ș ɂ ȣë˨ł&/ ê" formatted_email ʬȈɧcʡ́΃/oʬ @name û @email ×ώΫ̼Ǭo˹Ƴ ɅƁ̧ıʬʡƹʣĺυIĒĔ def formatted_email "#{@name} <#{@email}>" end Ċ" @name û @email χȘŃd×ώIJ @ ˞äƺˁƺGđ formatted_email Ȉɧ̢³àʡ ƴHƾŽǧ§á±ΙrequireΪȃIŃϥcʡ Ϊ˨ >> require './example_user' # Pž example_user Û*'ĢĜÞ­ => true >> example = User.new => # >> example.name # Ƅs nilt attributes[:name] â nil => nil >> example.name = "Example User" # Ŷ8 Ƨ nil Ĝj‹ => "Example User" >> example.email = "user@example.com" # Ŷ8 Ƨ nil ĜęŠƐ*xy => "user@example.com" >> example.formatted_email => "Example User " ΪɛEʼʬʁä .đ Unix Ǚ“ƈªʲƉ”'./example_user' õ͡ Ruby đƈªʲƉōDžΪȃI ǦȱʬEʼ ż/ ˓ʡƹʈëιΣʳǦ΃óʴŷʬşƟȱǫeDʬêĻûʣĺυIĒĔĊ"Ȥ attr_accessor ƺGƼ̞΃oƴHΝ~ example.name = "Example User" ȒRuby RLj @name ×ώʬo͝ " "Example User"email şƟ˨WʈëŗàGđ formatted_email cʡ 122 - Į 4 ī Rails ŌkĜ Ruby 4.3.4 ̩@˽ΣIJȷȣë ÏȁȘýŪàGʵʦ̪ǖäƴHàGLj Ͻ{ł&ıʬýŪŚ initialize ȈɧŒ ż ʡƹ >> user = User.new(name: "Michael Hartl", email: "mhartl@example.com") => # >> user.formatted_email => "Michael Hartl " B˟ 7 ˜ŽĶƴHRcʡýŪ¡Ķ»ŌͶΪˋLJȫßs“DŽώ΃o”mass assignmentđ Rails Ƒŭ ͆ 4.5. –Ŀ ʜđŌ Ruby ͪ͏ʬ@˽̀ȯ/˟ 5 ˜Rıı¤ʡΪ8ʺ͠ȱŽÔɼˁŷʡ ƴHRcʡ 4.4.5 ̩ żʬ example_user.rb ȃIƺGƴż͖Ljľ¢Ϫ $ rm example_user.rb ʈëLj…Dʬǹ³ǫ9¦EʼCŶŒǨδ¦ Bitbucketʈëφ̑¦ Heroku $ git status $ git commit -am "Add a full_title helper" $ git push $ bundle exec rake test $ git push heroku 4.5.1. ُêīM! • Ruby ǫe/ƑĥġʞĻ˞ ʬȈɧ • đ Ruby  ›ʭŌͶ • đ Ruby ł&Ȉɧcʡ def ƒϗĻ • đ Ruby ł&˨cʡ class ƒϗĻ • Ruby ŠżǷǘʬȁǟ˨ėȤȁ˹oęûýŪ • Ruby ĖȘ ˋɿɫʬͪ͏ǦÚàGξËàȶ$ʬȁǟ˨ė • ˞äȘ ˋȾ͘ûĻ˞ ˨WXɥȤЁĤʬȯ̌ • Ruby ǷǘŌͶ̄dž • àGƾŽŲkǹ Ruby Šżʬ˨ • “deified”Șĉȃ 4.6. ļ 1. LjEʼɴà 4.14 ʬϝäǞƳèεʬȈɧ̀è splitshuffle û join Ńʜ ™ȁLjĻ˞  ʬĻ˞Ϻŵƾ. 2. ÏʉEʼɴà 4.15Lj shuffle Ȉɧɳ±¦ String ˨ 4.5. –Ŀ - 123 3. żýŪš¥úê" person1person2 û person3Ljêûķ΃ó :first û :last ϗʈë ż ê" params ʬýŪ͔ params[:father] Ōŷ person1params[:mother] Ōŷ person2 params[:child] Ōŷ person3Ј͟  params[:father][:first] ʬoȘïɗˀ 4. Dž đ˷ʏ Ruby API ȃɈ/͍ýŪʬ merge Ȉɧʬʡɧ϶Ϊ̿ΠƁʬ͑ˤ̀ȷȘ>% { "a" => 100, "b" => 200 }.merge({ "b" => 300 }) 'ĢĉX 4.14»‹ĭEÙĜưñ >> def string_shuffle(s) >> s.?('').?.? >> end >> string_shuffle("foobar") => "oobfra" 'ĢĉX 4.15ĈPM String ijĜ shuffle Þăưñ >> class String >> def shuffle >> self.?('').?.? >> end >> end >> "foobar".shuffle => "borafo" 124 - Į 4 ī Rails ŌkĜ Ruby

    Top_arrow
    回到顶部
    EEWORLD下载中心所有资源均来自网友分享,如有侵权,请发送举报邮件到客服邮箱bbs_service@eeworld.com.cn 或通过站内短信息或QQ:273568022联系管理员 高进,我们会尽快处理。