$30 off During Our Annual Pro Sale. View Details »

Ruby on Railsの開発環境をつくってみよう! / GMO HosCon #19 Tokyo

Ken’ichiro Oyama
July 17, 2018
870

Ruby on Railsの開発環境をつくってみよう! / GMO HosCon #19 Tokyo

Ken’ichiro Oyama

July 17, 2018
Tweet

Transcript

  1. λʔϛφϧͬͯԿʁ w จࣈͰ.BD#PPL΍ͦͷଞ͍Ζ͍ΖϓϩάϥϜΛૢ࡞͢ΔͨΊͷϞϊɾπʔϧɾΞϓ Ϧέʔγϣϯ ◦ CUIʢΩϟϥΫλʔɾϢʔβɾΠϯλʔϑΣʔε : จࣈUIʣ ◦ ൓ରʹϚ΢εͰΫϦοΫͨ͠Γը໘Ͱͷૢ࡞͕͋Δͷ͸GUIʢάϥϑΟΧϧɾϢʔ

    βɾΠϯλʔϑΣʔε : άϥϑΟΧϧͳUIʣ • ίϚϯυ΍εΫϦϓτʢϓϩάϥϜ͕ղऍͰ͖ΔจࣈྻʣΛೖྗ͢Δ͜ͱͰ༷ʑͳૢ ࡞͕Ͱ͖Δ • ͳΜͰλʔϛφϧʁ ◦ ίϚϯυ͕จࣈͳͷͰϋοΩϦ͍ͯ͠Δͷ͕޷·Ε͍ͯΔ ◦ ʮ**ͱ͍͏ίϚϯυΛ࣮ߦͯ͠Έͯʯ ɹɹɹλʔϛφϧɺ#BTI  
  2. ϓϩάϥϛϯάݴޠ3VCZͷΠϯετʔϧ > brew install readline ruby-build rbenv > brew install

    mysql # MySQLͷΠϯετʔϧ > echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile > echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile > source ~/.bash_profile > rbenv install 2.5.1 > rbenv global 2.5.1 > ruby -v   ɹɹɹl.BD3VCZSCFOWz
  3. όʔδϣϯ؅ཧπʔϧ(JUͷΠϯετʔϧ > brew install git > git config --global user.name

    "[໊લΛೖΕ͍ͯͩ͘͞]" > git config --global user.email "[ϝʔϧΞυϨεΛೖΕ͍ͯͩ͘͞]" > git --version ɹɹɹ(JU  
  4. σʔλϕʔεͷ઀ଓઃఆΛ͠Α͏ default: &default adapter: sqlite3 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5

    } %> timeout: 5000 development: <<: *default database: db/development.sqlite3 test: <<: *default database: db/test.sqlite3 production: <<: *default adapter: mysql2 database: [ϚωΫϥͷϓϩδΣΫτը໘Λ֬ೝ] username: [ϚωΫϥͷϓϩδΣΫτը໘Λ֬ೝ] password: [ϝϞͨ͠σʔλϕʔεͷύεϫʔυ] host: [ϚωΫϥͷϓϩδΣΫτը໘Λ֬ೝ]  
  5. ϓϩδΣΫτͷιʔείʔυΛίϛοτ͠Α͏ wόʔδϣϯ؅ཧπʔϧ(JUΛར༻ͯ͠ࠓ·ͰͷιʔείʔυΛه࿥ʢί ϛοτʣ͠·͢ > git init # σΟϨΫτϦΛGitͰ؅ཧ͢ΔΑ͏ʹઃఆ > git

    add . # શͯͷ௥Ճͯ͠Α͍ϑΝΠϧΛGitʹ؅ཧͤ͞Δ > git commit -m 'My First Commit’ # ίϛοτ > git log # ίϛοτͷϩάΛ֬ೝ ɹɹɹlHJUJOJUlHJUMPHz  
  6. ιʔείʔυΛमਖ਼ͯ͠ίϛοτ͠Α͏ wϒϥ΢βͰIUUQMPDBMIPTUJEFBT ʹΞΫηεͯ͠ΈΑ͏ > rails generate scaffold idea name:string description:text

    picture:string # ideas ςʔϒϧΛ࡞ͬͯૢ࡞͢ΔͨΊͷίʔυΛੜ੒ > rails db:migrate # ideas ςʔϒϧΛ࡞੒ > rails server # αʔόΛىಈ ɹɹɹlSBJMTίϚϯυzl$36%zlTDB⒎PMEz  
  7. ιʔείʔυΛमਖ਼ͯ͠ίϛοτ͠Α͏ wSBJMTHFOFSBUFͰࣗಈͰߦΘΕͨमਖ਼Λ(JUΛར༻ͯ֬͠ೝɾه࿥ ʢίϛοτʣ͠Α͏ > git status # ιʔείʔυͷมߋঢ়ଶΛ֬ೝͰ͖·͢ > git

    diff # ιʔείʔυͷࠩ෼Λ֬ೝͰ͖·͢ > git add . > git commit -m 'My Second Commit' > git log ɹɹɹl(JUίϚϯυz  
  8. σϓϩΠલͷલ४උ 44)ͷެ։伴ͷઃఆ wެ։伴ͱൿີ伴ͷରΛ࡞੒ͯ͠ɺެ։伴ΛΫϦοϓϘʔυʹίϐʔ͠ ·͢ > install -m 0700 -d ~/.ssh

    # σΟϨΫτϦͷ࡞੒ > ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa # ެ։伴ͱൿີ伴Λ࡞੒ > cat ~/.ssh/id_rsa.pub | pbcopy # ެ։伴ΛΫϦοϓϘʔυʹίϐʔ ɹɹɹlDBUίϚϯυlQCDPQZz  
  9. ϥΠηϯε w͜ͷϋϯζΦϯͷࢿྉͷҰ෦͸3BJMT(JSMTΨΠυ ೔ຊޠ൛  IUUQ SBJMTHJSMTKQ Λࢀߟʹ͍ͯ͠·͢ɻ·ͨɺ3BJMT(JSMTΨΠυʹͭͳ͕ ΔΑ͏ʹ࡞ΒΕ͍ͯ·͢ɻ 3BJMT(JSMTΨΠυϥΠηϯε 5IJTXPSLJTMJDFOTFEVOEFSB$SFBUJWF$PNNPOT"UUSJCVUJPO4IBSF"MJLF-JDFOTF

    IUUQDSFBUJWFDPNNPOTPSHMJDFOTFTCZTB 3BJMT(JSMT IUUQ SBJMTHJSMTDPN u$SBGUFEXJUIFYDJUFNFOUGSPN)FMTJOLJ 'JOMBOEu'PMMPXVTPO5XJUUFS IUUQTUXJUUFSDPNSBJMTHJSMT BOE'BDFCPPL IUUQTXXXGBDFCPPLDPNSBJMTHJSMT   
  10. ιʔείʔυΛमਖ਼ͯ͠ίϛοτ͠Α͏ > brew cask install sequel-pro # MySQL؅ཧπʔϧͷΠϯετʔϧ > brew

    install mysql-client > brew services mysql start # MySQLͷىಈ > brew services list ɹɹɹl.Z42-zlσʔλϕʔεzl4FRVFM1SPz  
  11. .Z42-ʹ઀ଓ͢ΔϢʔβΛ࡞੒͢Δ > mysql -uroot mysql> CREATE USER myuser@localhost identified with

    mysql_native_password by ‘mypass'; mysql> exit > ɹɹɹl.Z42-zlσʔλϕʔεzl4FRVFM1SPz   w ࠷৽ͷ.Z42-Ͱ͸σϑΥϧτͷೝূํ͕ࣜDBDIJOH@TIB@QBTTXPSEͱͳ͓ͬͯΓ4FRVFM1SPͳͲ͕ ରԠ͍ͯ͠ͳ͍ͨΊɺ.Z42-ҎલͰར༻͞Ε͍ͯͨNZTRM@OBUJWF@QBTTXPSEΛར༻ͨ͠ϢʔβΛ࡞ ੒͍ͯ͠·͢
  12. σʔλϕʔεͷ઀ଓઃఆΛ͠Α͏ default: &default adapter: mysql2ɹ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5

    } %> timeout: 5000 development: <<: *default ɹusername: root database: hoscon host: 127.0.0.1 test: <<: *default username: root database: hoscon_test host: 127.0.0.1 production: <<: *default database: [ϚωΫϥͷϓϩδΣΫτը໘Λ֬ೝ] username: [ϚωΫϥͷϓϩδΣΫτը໘Λ֬ೝ] production: <<: *default database: [ϚωΫϥͷϓϩδΣΫτը໘Λ֬ೝ] username: [ϚωΫϥͷϓϩδΣΫτը໘Λ֬ೝ] password: [ϝϞͨ͠σʔλϕʔεͷύεϫʔυ] host: [ϚωΫϥͷϓϩδΣΫτը໘Λ֬ೝ]