Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby and Rails補足資料 #TechLunch

Ruby and Rails補足資料 #TechLunch

2012/03/28(水) @ Livesense TechLunch
発表者:松坂 高嗣

Livesense Inc.

April 23, 2014
Tweet

More Decks by Livesense Inc.

Other Decks in Technology

Transcript

  1. ͜ͷυΩϡϝϯτʹ͍ͭͯ Ruby on Rails Λར༻ͨ͠ɺϦϒηϯεΠϯϑϥͰ࣮ߦՄೳͳ Web ΞϓϦέʔγϣϯ։ൃʹ͍ͭͯɺิ଍ࣄ߲Λ·ͱ Ί͍ͯ·͢ɻ࡞੒தͷ։ൃΨΠυΑΓ΋ͣͬͱڊେͳ Appendix Ͱ͢ɻ

    ຊΨΠυϥΠϯͷ಺༰͸׬શͳ΋ͷͰ͸͋Γ·ͤΜɻదٓमਖ਼ɺมߋ͞Ε͍͖ͯ·͢ɻ ର৅ಡऀ ͜ͷυΩϡϝϯτ͸ҎԼͷΑ͏ͳಡऀΛ૝ఆ͠·͢ɻ ‣Ϧϒηϯεࣾ಺Ͱಈ࡞͢Δ Web ΞϓϦέʔγϣϯΛ։ൃ͠Α͏ͱ͍ͯ͠Δਓ ‣Web ΞϓϦέʔγϣϯʹ͍ͭͯे෼ͳཧղ͕͋Δ͕ Ruby on Rails ʹ͸͋·Γ৮Εͨࣄ͕ແ͍ਓ ໨࣍ Rubyʹ͍͍ͭͯΖ͍Ζ 2 Rails ͋Ε͜Ε 11 ։ൃ؀ڥͳͲ΋Ζ΋Ζ 16 ͍ͭͰʹ༗༻ͳϥΠϒϥϦɾখωλ 20 Ruby and Rails ิ଍ࢿྉ Ruby and Rails ิ଍ࢿྉ
  2. Rubyʹ͍͍ͭͯΖ͍Ζ Ruby ͸ࠃ࢈ϓϩάϥϛϯάݴʢུʣ ͜ͷઆ໌ʹ͍ͭͯ͸ɺ͍͓ͪ͏ɺRuby ͷ࿩ʹ͸͖ͭ΋ͷͳͷͰɻ ࠷ۙ·ͭ΋ͱΏ͖ͻΖʢmatzʣࢯ͕ FSF͔ΒԿ͔৆΋Β͍ͬͯ·ͨ͠Ͷɻ 2012೥ݱࡏɺ΍΍γΣΞ͸௿Լத http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html (TIOBE)

    Javaਓؾ͸มΘΒͣɻ PL/SQLͷܹ૿͸࠷ۙͷʮϏοάσʔλʯτϨϯυʹͷͬͨ΋ͷͰ͠ΐ͏͔ɻ Rails ͷීٴͰ Ruby ͷγΣΞ͸૿͑·͕ͨ͠ɺWebΞϓϦʹݶΒͣ DSLతͳ෼໺Ͱ͸͍Ζ͍Ζ࢖ΘΕ͍ͯΔΑ͏Ͱ ͢ɻ໘ന͍ͱ͜ΖͩͱɺRPGπΫʔϧ͕಺෦هड़༻ͷεΫϦϓτݴޠͱͯ͠ Ruby Λ࠾༻ͯͨ͠Γͯ͠·ͨ͠ɻ෱Ԭݝ ओಋͰ૊ΈࠐΈ ruby ͳͲΛ͕Μ͹ͬͯΔϓϩδΣΫτ΋͋Γ·͢ɻ Ruby ͷυΩϡϝϯτࢀরઌ ‣http://www.ruby-lang.org/ja/ : Ruby ެࣜαΠτ Ruby and Rails ิ଍ࢿྉ Ruby and Rails ิ଍ࢿྉ
  3. ‣http://doc.ruby-lang.org/ja/ : ΔΓ·ʢRuby Reference Manualʣ ‣http://rurema.clear-code.com/ : ΔΓ·αʔν αϙʔτ͞Ε͍ͯΔόʔδϣϯ͸ 1.9.3

    ϦϒηϯεͷΠϯϑϥͰαϙʔτ͞ΕΔ Ruby όʔδϣϯ͸ 2012೥3݄ݱࡏͰ 1.9.3 Ͱ͢ɻಛʹཧ༝͕ͳ͚Ε͹ 1.8ܥ Ͱ͸ͳ͘1.9ܥΛಋೖ͍ͯͩ͘͠͞ɻ ‣http://jp.rubyist.net/magazine/?FirstStepRuby : Ruby Magazine هࣄ Ҏલͷόʔδϣϯʢ1.8ܥʣͱͷࠩҟ require ͢Δࡍɺϩʔυύεʹ current σΟϨΫτϦؚ͕·Εͳ͘ͳΓ·ͨ͠ɻͦͷͨΊɺ૬ରύεͰଞͷϑΝΠϧΛ ಡΈࠐΜͰ͍ΔεΫϦϓτ͸ಈ࡞͠ͳ͘ͳΔέʔε͕͋Γ·͢ɻ ίʔυதʹϚϧνόΠτจࣈྻΛ࢖͍ͬͯΔ৔߹ɺϚδοΫίϝϯτΛ෇༩͠ͳ͍ͱΤϯίʔσΟϯάΤϥʔͱͳΓ· ͢ɻ ͦͷଞɺϒϩοΫҾ਺ͷείʔϓ͕มߋʹͳͬͨΓɺจࣈྻ͕όΠτ୯Ґɾจࣈ୯ҐͰҟͳΔऔΓग़͠ํ͕Ͱ͖ΔΑ ͏ʹͳͬͨΓ͍ͯ͠·͢ɻ ‣http://jp.rubyist.net/magazine/?0025-FirstStepRuby191 : Ruby 1.9.1 ͷา͖ํ ‣http://www.oreilly.co.jp/community/blog/2009/05/changes-on-ruby-1-9.html : Ruby 1.9 ʹى͖ͨมԽ Ruby ͸ΠϯλϓϦλܕͷεΫϦϓτݴޠͰ͢ ίϯύΠϧܕͰ͸ͳ͍ͷͰɺॻ͍ͯ→ಈ͔ͯ͠→मਖ਼ͯ͠ɺͱ͍͏ϓϩηεΛૉૣ͘ճͤ·͢ɻ ର࿩ܕͷ࣮ߦ΋αϙʔτ͞Ε͍ͯ·͢ɻର࿩ܕ࣮ߦ͸ irb ίϚϯυͰ͢ɻҎԼ͸ irb ίϚϯυΛར༻ͨ͠ಈ࡞֬ೝͷྫ Ͱ͢ɻม਺ a ʹ਺஋ 1Λઃఆ͠ɺͦͷΫϥεΛ֬ೝ͠ɺϝιουͷҰཡ͔Βʮto_ʯΛؚΉ΋ͷΛग़ྗ͍ͯ͠·͢ɻ $ irb 1.9.3-p0 :001 > a = 1 => 1 1.9.3-p0 :002 > a += 2 => 3 1.9.3-p0 :003 > a.class => Fixnum 1.9.3-p0 :004 > a.methods.grep /to_/ => [:to_s, :to_f, :to_i, :to_int, :to_r, :to_c, :respond_to_missing?, :to_enum] Ruby and Rails ิ଍ Ruby and Rails ิ଍
  4. Ruby ͸ಈతͳΫϥεࢦ޲ͷΦϒδΣΫτࢦ޲ϓϩάϥϛϯάݴޠͰ͢ Ϋϥεࢦ޲ͷΦϒδΣΫτࢦ޲ ϓϩάϥϜͷେ൒͸ΫϥεΛઃܭ͠ɺ·ͨଞͷΫϥεͷΠϯελϯεΛ࡞੒ͯ͠ར༻͢ΔίʔυʹͳΓ·͢ɻ ҎԼʹɺ͋Γ͕ͪͳ Χ΢ϯλʔΛ࡞੒͢ΔϓϩάϥϜΛࣔ͠·͢ɻҎԼɺઆ໌͸؆୯ͳ΋ͷͳͷͰඈ͹ͯ͠΋໰୊͋ Γ·ͤΜɻ #-*- coding:utf-8 -*-

    # Ϋϥεఆٛ class MyCounter attr_reader :counter def initialize @counter = 0 end def add @counter += 1 end end # Πϯελϯε࡞੒ɹׅހ͸ᐆດ͞ճආͷͨΊʹ͚ͭͯ΋͍͍͠ɺলུͯ͠΋͍͍ c = MyCounter.new() puts 'init!' puts c.counter #=> 0 c.add c.add puts 'after 2 times add.' puts c.counter #=> 2 ͬ͟ͱಡΜͩࡍʹಛ௃తͳͷ͸ίʔυϒϩοΫʢʮϒϩοΫʯͱ͍͏༻ޠʹ͸ ruby Ͱ͸ಛผͳҙຯ͕͋Γ·͢ͷͰɺ ͜͜Ͱ͸ᐆດ͞Λճආ͢ΔͨΊίʔυϒϩοΫͱݺͼ·͢ʣͷऴ͕ྃதׅހͰ͸ͳ͘ end ͱ͍͏Ωʔϫʔυʹͳ͍ͬͯ Δ͜ͱɺҾ਺ͷͳ͍ϝιουݺͼग़͠ͷׅހ͕লུ͞Ε͍ͯΔ͜ͱɺίϯετϥΫλ͕ initialize ͱ͍͏໊শͰ͋ Δ͜ͱɺΠϯελϯεม਺͕ʮ@ʯϓϨϑΟοΫεΛ൐͍ͬͯΔ͜ͱɺΠϯελϯεͷੜ੒͕Ϋϥεͷ new Ϋϥεϝ ιουͰߦΘΕ͍ͯΔ͜ͱͰ͠ΐ͏͔ɻ ͜ͷίʔυΛ֬ೝ͢ΔݶΓɺಛผށ࿭͏෦෼͸ͳ͍ͱࢥ͍·͢ɻ Ұ͚ͭͩͻ͔͔ͬΔͷ͸ΫϥεͰଐੑΛఆ͍ٛͯ͠Δ attr_reader ͷݺͼग़͠Օॴͩͱࢥ͍·͢ɻ attr_reader ͸ʮଐੑΛఆٛ͢ΔΫϥεϝιουʯͰ͢ɻݴޠػೳͰ͸ͳ͘ɺClassΫϥεͷΠϯελϯεϝιουͰ ͢ɻ͜ͷϝιου͸Ҿ਺ͱͯ͠౉໊ͨ͠લͷΠϯελϯεม਺ʹର͢ΔಡΈऔΓઐ༻ͷΞΫηαϝιουΛੜ੒͠· ͢ɻ attr_readerϝιουͷҾ਺ͱͯ͠౉͍ͯ͠Δ :counter ͸γϯϘϧͱݺ͹Εɺruby ͷίʔυ಺Ͱར༻͞ΕΔʮจࣈ Ruby and Rails ิ଍ Ruby and Rails ิ଍
  5. ྻͷΑ͏ͳ΋ͷʯͰ͢ɻ಺෦తʹ͸͍ΘΏΔ enum ͷΑ͏ʹ਺஋Խ͞Εͯ؅ཧ͞Ε͓ͯΓɺՄಡੑ͕ߴ͘ൺֱ͕ߴ଎Ͱ ͢ɻϝιου໊ͳͲ͸಺෦తʹγϯϘϧͱͯ͠؅ཧ͞Ε͍ͯ·͢ɻ ‣http://doc.ruby-lang.org/ja/1.9.3/class/Symbol.html : class Symbol ಈతͳΫϥεࢦ޲ Ruby

    ͷੈքʹ͸͍ΘΏΔؔ਺΍ϓϩύςΟ͕͋Γ·ͤΜɻखଓ͖͸શͯʮϝιουʯͰ͋Γɺม਺ͱఆ਺Ҏ֎ͷશ ͯͷࢀর͸࣮ࡍʹ͸ϝιουݺͼग़͠Ͱ͢ɻ·ͨɺύϒϦοΫͳΠϯελϯεม਺͕ఆٛͰ͖·ͤΜɻ͜͏ͨ͠࢓༷ͷ γϯϓϧ͞ͱɺهड़ͷࣗ༝౓ͷߴ͕͞ Ruby ͷಛ௃Ͱ͢ɻ Ϋϥε΍Ϟδϡʔϧͷఆٛ͸ಈతͰ͢ɻύϒϦοΫɾϓϥΠϕʔτΛ໰Θͣɺඪ४ΫϥεϥΠϒϥϦͷϝιου΍ Rails ͷఏڙ͢Δϝιου΋શͯϢʔβʔίʔυʹΑͬͯஔ͖׵͑Δࣄ͕ग़དྷ·͢ɻ·ͨɺ͋ΔಛఆͷΦϒδΣΫτʹͩ ͚ϝιουΛޙ͔Β௥Ճ͢Δ͜ͱ΋ՄೳͰ͢ɻΫϥεͰ͸ͳ͘Πϯελϯεʹ௚઀௥Ճ͞ΕΔϝιου͸ಛҟϝιου ͱݺ͹Ε·͢ɻ ϝιουΛఆٛ͢Δϝιου Ruby ͷඪ४తͳ։ൃʹ͓͍ͯ΋ɺΠϯελϯεม਺ʹର͢ΔΞΫηοαϝιουΛఆٛ͢ΔͨΊͷ attr_accessor Ϋ ϥεϝιουͳͲ͕Α͘ར༻͞Ε·͢ɻ ݺͼग़͞ΕͨҾ਺໊ͰϝιουΛ࡞੒͢Δɺϝιου͕ଘࡏ͠ͳ͚Ε͹࡞੒͢Δɺͱ͍ͬͨૢ࡞͸ Rails ͷ࣮૷ͷத Ͱ΋ଟ͘ߦΘΕ͍ͯ·͢ɻ ࣾ಺ͷຊ୨ʹ͋Δ ϝλϓϩάϥϛϯά ruby ͳͲʹඇৗʹৄ͘͠ࡌ͍ͬͯ·͢ɻ ‣http://reference.jumpingmonkey.org/programming_languages/ruby/ruby-metaprogramming.html : metaprogramming Nil ΋ΫϥεͰΦϒδΣΫτͰ nil ΋·ͨ NilClass ͷΠϯελϯεͰ͢ɻ ඪ४ϥΠϒϥϦͰ΋͍͔ͭ͘ͷม׵ϝιουʹ͸ nil Ϋϥεʹ΋ఆٛ͞Ε͍ͯΔ΋ͷ͕͋ΓɺnilͷνΣοΫΛলུ͠ ͨهड़͕Ͱ͖ΔΑ͏ʹઃܭ͞Ε͍ͯ·͢ɻ ҎԼͷྫ͸ΦϒδΣΫτΛ഑ྻʹม׵͢Δ to_a ϝιουͱ int ܕʹม׵͢Δ to_i ϝιουͷڍಈͰ͕͢ɺnilʹؔͯ͠ ͸௚ײʹଈͨ݁͠ՌΛฦ͢Α͏ͳಈ࡞Λ͍ͯ͠Δ͜ͱ͕Θ͔Γ·͢ɻ a = nil => nil a.to_a => [] a.to_i => 0 Ruby and Rails ิ଍ Ruby and Rails ิ଍
  6. rails Λ͸͡Ίଟ͘ͷϥΠϒϥϦͰ͸ NilClass ʹ͍͔ͭ͘ϝιουΛ௥Ճ͢Δ͜ͱʹΑͬͯɺNullObject ύλʔϯͷΑ ͏ͳهड़͕Մೳʹ͍ͯ͠·͢ɻ if data_object.present? puts ‘data

    object is not nil , “” , or [] ,{} ’ end ͜Ε͸ඪ४ϥΠϒϥϦͷಈ࡞Λॻ͖׵͑ΔҰͭͷྫͰ͢ɻ ϝιουΛผͷϝιουݺͼग़͠ʹมߋͯ͠͠·ͬͨΓɺΫϥεͷܧঝߏ଄Λมߋͨ͠ΓͳͲ͔ͳΓͳΜͰ΋͋Γͳ ͷͰɺෆ༻ҙʹ࢖͏ͱ୭΋ҙਤ͕ಡΊͳ͍ʢ݁Ռ΋૝૾Ͱ͖ͳ͍ʣίʔυ͕؆୯ʹ࡞੒Ͱ͖·͢ɻ จࣈྻ͕มߋՄೳͰ͢ JavaͳͲ͔Β͘Δͱ͜ͷ͋ͨΓ͕ෆࢥٞͳҹ৅Λड͚·͢ɻ ͭ·Γɺ͜ͷΑ͏ʹͳΔͱ͍͏͜ͱͰ͢ɻ 1.9.3-p0 :007 > name = "Hello" => "Hello" 1.9.3-p0 :008 > name_ref = name => "Hello" 1.9.3-p0 :009 > name_ref.sub!("He" , "Fa") => "Fallo" 1.9.3-p0 :010 > name => "Fallo" ͳ͓ɺจࣈྻ΍HashͳͲΛ࡞੒ޙɺมߋෆೳʹ͢Δ freeze ϝιου͕༻ҙ͞Ε͍ͯ·͢ɻfreeze ϝιου͕ݺͼग़͞ ΕͨΦϒδΣΫτʹഁյతϝιουͷݺͼग़͠Λߦ͓͏ͱ͢Δͱྫ֎͕εϩʔ͞Ε·͢ɻ ಈతͳଆ໘͕ڧ͗ͯ͋͢·ΓIDEͷࢧԉ͕ड͚ΒΕ·ͤΜ ͜͏͍ͬͨʮಈతͳʯੑ࣭ʹΑΓɺruby ϓϩάϥϜ͸͠͹͠͹σόοά͕ࠔ೉Ͱ͢ɻ ݴޠͷػೳ͚ͩͰ͸ͳ͘ɺจԽతʹಈతͳಛੑΛར༻͢Δࣄ͕ଟ͍͔Βͱ͍͏෦෼͕େ͖͍Ͱ͢ɻͨͱ͑͹ɺҎԼͷ Α͏ͳϞδϡʔϧΛIDEͷཱ৔͔ΒಡΈࠐΜͰίʔυิ׬ର৅ʹ͢Δ͜ͱ͕༰қͰͳ͍ࣄ͸͙͢ʹΘ͔Γ·͢ɻαϯϓ ϧͳͷͰɺίʔυͷࡉ͔͍ͱ͜Ζ͸ؾʹ͠ͳ͍Ͱ͍ͩ͘͞ɻ module CompositeModule # ಡΈࠐΉϞδϡʔϧͷϕʔγοΫͳϦετ COMPOSITE_MODULES=["moduleA","moduleB","moduleC","moduleD",] # ؀ڥʹԠͯ͡ಡΈࠐΉϞδϡʔϧΛมߋ͢Δ if env['linux'] COMPOSITE_MODULES << 'linux-support-module' end Ruby and Rails ิ଍ Ruby and Rails ิ଍
  7. if env['test'] COMPOSITE_MODULES << 'test-support-module' end # ϞδϡʔϧΛಡΈࠐΉ COMPOSITE_MODULES.each do

    |module_name| require module_name include(eval(module_name)) end end ྨࣅͷίʔυ͸ Rails ίΞͷ͍ΖΜͳͱ͜ΖͰग़͖ͯ·͢ɻ ҰͭͷΫϥεͷػೳΛෳ਺ͷϑΝΠϧ΍ϞδϡʔϧͰ࣮૷͢Δ͜ͱ΋͘͝ී௨ʹߦΘΕΔͨΊɺPHPͱEclipse ͷ૊Έ ߹ΘͤͰظ଴Ͱ͖ΔΑ͏ͳIDEͷڧྗͳೖྗࢧԉ౳͸ͦΕΛҙਤͨ͠ઃܭΛ͠ͳ͚Ε͹೉͍͠ͱࢥ͍·͢ɻ ؀ڥʹΑͬͯϞδϡʔϧΛ੾Γସ͑Δͱ͍͏ͷ͸ CݴޠܥྻͰ͸Α͘΍Δ͜ͱͰ͢ͷͰɺ͋Δ͍͸ڻ͘ʹ͸౰ͨΒͳ ͍ͷ͔΋͠Ε·ͤΜɻ Ruby ͷੈքͰ͸ผͷϞδϡʔϧΛ include ͢Δ Mix-in จԽ͕੝ΜͰ͢ Mix-in ͸͍ΘΏΔ࣮૷ܧঝͰ͕͢ɺis-a ؔ܎Λද͢ʮΫϥεͷܧঝʯͱ͸ҙຯ͕ҟͳΓ·͢ɻ ্ड़ͷʮΫϥε΍Ϟδϡʔϧͷఆ͕ٛಈతʯʹ΋ؔ࿈͠·͕͢ɺRuby Ͱ͸ Module ͱ͍͏࣮૷୯Ґ͕͋Γ·͢ɻ Classͷ਌ΫϥεͰ͋ΓɺΠϯελϯεΛ࣋ͭࣄ͕Ͱ͖ͳ͍Ҏ֎͸ Class ͱಉ༷ͷػೳΛ࣋ͪ·͢ɻ Class ΋ؚΊͯશͯͷϞδϡʔϧ͸ผͷϞδϡʔϧΛʮincludeʯ͢Δ͜ͱ͕Ͱ͖·͢ɻ͢Δͱɺinclude ͨ͠Ϟδϡʔ ϧͷϝιουΛࣗ෼ʹ௥Ճ͢Δ͜ͱ͕Ͱ͖·͢ɻ͜͏͍ͬͨ࢖ΘΕํΛ૝ఆͨ͠Ϟδϡʔϧͷ͜ͱΛ Mix-in ͱݺͼ· ͢ɻ Mixinͱ͸ΦϒδΣΫτࢦ޲ϓϩάϥϛϯάݴޠʹ͓͍ͯɺαϒΫϥεʹΑͬͯܧঝ͞ΕΔ͜ͱʹΑΓػೳΛఏڙ͠ɺ ୯ମͰಈ࡞͢Δ͜ͱΛҙਤ͠ͳ͍ΫϥεͰ͋ΔɻMixin ͔Βͷܧঝ͸ɺಛԽͷҰܗଶͰ͸ͳ͘ɺΉ͠ΖػೳΛଞͷΫ ϥε͔ΒूΊΔͨΊͷखஈͰ͋Δɻ͋ΔΫϥε͸ଟॏܧঝʹΑΓෳ਺ͷ Mixin Ϋϥε͔ΒܧঝΛߦͬͯɺେ൒ͷػೳ ΛܧঝʹΑ࣮ͬͯݱ͢Δ͜ͱ͕Ͱ͖Δɻ Mixin : Wikipedia ͜Ε͸σʔλܕͷσʔλϞσϧͦͷ΋ͷͱɺந৅తͳૢ࡞Λ෼཭ͯ͠͠·͏͜ͱΛՄೳʹ͠·͢ɻ Θ͔Γ΍͍͢Ұͭͷྫͱͯ͠ɺEnumerable Ϟδϡʔϧ͕͋Γ·͢ɻ Ruby and Rails ิ଍ Ruby and Rails ิ଍
  8. ͜Ε͸܁Γฦ͠ՄೳͳΦϒδΣΫτʹର͢Δૢ࡞Λ·ͱΊ͍ͯΔϞδϡʔϧͰ͢ɻArray ΍ Set ͱ͍ͬͨू߹Λද͢Ϋ ϥε͸ࣗ෼ͷཁૉʹ܁Γฦ͠ΞΫηε͢ΔͨΊͷΠϯλʔϑΣΠε each Λ༻ҙ্ͨ͠ͰɺEnumerable ϞδϡʔϧΛܧ ঝ͠·͢ɻ͢ΔͱɺEnumerable ϞδϡʔϧͰఆٛ͞Εͨϝιου͕ࣗ෼ࣗ਎ͷ

    each ϝιουΛ௨ͯ͡ػೳ͢ΔΑ͏ʹ ͳΓ·͢ɻ Enumerable ͸ ʮfirstʯ΍ʮsortʯͳͲɺeach Λ಺෦Ͱར༻ͯ͠ಈ࡞͢ΔϝιουΛෳ਺ఆ͍ٛͯ͠·͢ɻ͜ΕΒ͸ Enumerable ΛجఈΫϥεͱ͢Δ͜ͱͰαϒΫϥεͰར༻Ͱ͖ΔΑ͏ʹͯ͠΋ಉ༷ͷಈ࡞Λ࣮ݱͰ͖·͢ɻ ͜͜ʹʮͲ͏ͯ͠௨ৗͷܧঝͰ͸ͳ͘ MixinʹΑΔ࣮૷ܧঝΛબ୒ͨ͠ͷ͔ʯͱ͍͏ٙ໰͕͋Γ·͢ɻMix-in Λ࠾༻ ͢Δ͜ͱͰɺEnumerable Ϟδϡʔϧ͸each ϝιουΛఆٛՄೳͳΫϥεͰ͋Ε͹ɺશͯͷέʔεͰར༻ՄೳʹͳΓ· ͨ͠ɻαϒΫϥεͰ਌Ϋϥεͷ಺෦ߏ଄ʹΞΫηε͢ΔͨΊͷΠςϨʔλΛ༻ҙ͢Δͱ͍͏ͷ͸Α͋͘ΔࣄͰ͢ɻ EnumerableΛجఈΫϥεʹ͢ΔσβΠϯͰ͸ɺͦΕΒͷέʔεʹରԠ͕೉͘͠ͳΓ·͢ɻσβΠϯύλʔϯͰ͍͏ʮҟ ͳΔΠϯλʔϑΣΠε΁ద߹ͤ͞Δʯͱ͍͏χʔζ͕ൃੜ͠·͢ɻEnumerable ͷΑ͏ͳ͖ΘΊͯ൚༻తͳػೳΛ࠶ར༻ Մೳʹ͢Δํ๏ͱͯ͠ɺحྷͳղܾࡦͰ͋Δͱࢥ͍·͢ɻ Ұͭ໰୊͕͋Δͱ͢Ε͹ɺEnumerable ϞδϡʔϧΛ include ͢Δଆ͸ɺeach ϝιουͳͲɺنఆͷϝιου͕ظ଴ ௨Γಈ࡞͠ͳ͚Ε͹ͳΒͳ͍ͱ͍͏͜ͱͰ͢ɻ͜ΕΛ੩తʹఆٛʢ੍໿ʣ͢Δ࢓૊Έ͸͋Γ·ͤΜɻΑ͘΋ѱ͘΋μο ΫλΠϐϯάͷੈքʹͳΓ·͢ɻ ઃܭͷࣗ༝౓͕ߴ͍෼ɺΨΠυϥΠϯ΍ઃܭϙϦγʔ͕ͳ͍ͱେม Java΍PHPͰ͋Ε͹ɺʮ͜͏ͨ͠ߏ଄ͷσʔλΞΫηεΛఏڙ͢ΔͨΊʹ͸ɺ͜ͷΑ͏ͳΫϥεߏ੒ʹ͢Δඞཁ͕͋ Δʯͱ͍͏ɺݴޠػೳͷ੍໿ͱͷؒͰ࣮૷্ͷܾఆ͕ߦΘΕΔ͜ͱ͕ଟ͍ͱࢥ͍·͢ɻͦͷ෼ɺʮਖ਼͍͠ʯઃܭ൑அ͕ ͠΍͍͢Ͱ͢ɻ Ruby ͷ৔߹ɺ࣮૷্ͷબ୒ࢶ͕ଟ͍෼ɺશମͰݟΔͱ੔߹ੑͷແ͍બ୒Λͯ͠͠·͏͜ͱ͕ΑΓ؆୯Ͱ͢ɻ ଞͷݴޠͰࣗવʹײ͡Δ੩తͳߏ଄ʹجͮ͘ઃܭΛߦ͍ɺ֦ு͕ඞཁʹͳͬͨ࣌ʹಈతͳύονΛ౰ͯΔࣄͰରॲ͢ Δɺͱ͍͏Α͏ͳ΍ΓํΛͱΔͱɺ༰қʹഁ୼͠·ͨ͠ɻ υΩϡϝϯτԽ͸RDocΛ࢖͍·͢ɻ ϝιουఆٛ΍ΫϥεఆٛʹنఆͷॻࣜͰίϝϯτΛೖΕ͓ͯ͘ͱɺυΩϡϝϯτԽͯ͘͠ΕΔ RDoc͕ඪ४Ͱఏڙ͞ Ε͍ͯ·͢ɻ http://ruby.gfd-dennou.org/tutorial/rdoc/ : RDocʹΑΔࣗಈυΩϡϝϯτੜ੒ Ruby and Rails ิ଍ Ruby and Rails ิ଍
  9. Rails ͋Ε͜Ε Ruby on Rails 2004೥ʹެ։͞Ε·ͨ͠ɻ Ruby on Rails͸σϯϚʔΫͷϓϩάϥϚͰ͋ΔDavid Heinemeier

    HanssonʹΑΓɺϓϩδΣΫτ؅ཧπʔ ϧ"basecamp"ͷ։ൃʹ༻͍ΒΕͨ஌ݟ΍ίʔυΛநग़͠ɺҰൠԽ͢Δ͜ͱʹΑΓ࡞੒͞Εͨɻ Ruby on Rails : Wikipedia Wikipediaʹ͋ΔʮRuby on RailsʢϧϏʔΦϯϨΠϧζʣ͸ΦʔϓϯιʔεͷWebΞϓϦέʔγϣϯϑϨʔϜϫʔΫͰ ͋Δɻʯͱ͍͏આ໌͸ෆे෼Ͱ͢ɻRuby on Rails ͸WebΞϓϦέʔγϣϯϑϨʔϜϫʔΫͱ໨తಛԽܕͷϥΠϒϥϦ ηοτɺςετεΠʔτɺ։ൃ༻ͷ֤छίϚϯυɾπʔϧɺ։ൃαʔόɺӡ༻ܥͷσʔλϕʔεϚΠάϨʔγϣϯίϚϯ υ·ͰΛηοτʹͨ͠؀ڥͰ͢ɻʮϓϩάϥϛϯάʯ͚ͩʹͱͲ·Βͳ͍ɺΞϓϦέʔγϣϯͷϥΠϑαΠΫϧશମΛ αϙʔτ͠·͢ɻ యܕతͳྫΛҎԼʹࣔ͠·͢ɻ $ rails new AppTest create create README.rdoc create Rakefile ... ϑΝΠϧ͕ੜ੒͞Ε͍͖ͯ·͢ ... run bundle install Fetching source index for https://rubygems.org/ ... ґଘؔ܎ϥΠϒϥϦ͕Πϯετʔϧ͞Ε·͢ ... $ cd AppTest $ rails s => Booting WEBrick => Rails 3.2.2 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2012-03-26 19:08:53] INFO WEBrick 1.3.1 ͜͜·ͰͷखॱͰɺ localhost:3000 Ͱ rails ΞϓϦέʔγϣϯͷ։ൃαʔό্ཱ͕͕ͪΓɺ WebΞϓϦέʔγϣϯʹΞ Ϋηε͢Δ͜ͱ͕Ͱ͖·͢ɻWEBrick͸ruby ૊ΈࠐΈͷ httpαʔόͰ͢ɻ࡞੒͞ΕͨAppTest σΟϨΫτϦҎԼʹ͸ɺ ΞϓϦέʔγϣϯͷඪ४తͳߏ੒ͷσΟϨΫτϦπϦʔ͕࡞੒͞Ε͓ͯΓɺ͙͢ʹίʔυΛॻ͖࢝ΊΔ͜ͱ͕Ͱ͖· ͢ɻ Ruby and Rails ิ଍ࢿྉ Ruby and Rails ิ଍ࢿྉ
  10. ͜͏͍ͬͨࢥ૝͕ Rails ΦϦδφϧͳ΋ͷ͔͸Θ͔Γ·ͤΜ͕ɺരൃతʹීٴͨ͠ͷ͸ Rails ͕ݪҼͰ͢ɻͦͷޙɺ symfony Ͱ͋Δͱ͔ django Ͱ͋Δͱ͔ɺӨڹΛड͚ͨͱࢥΘΕΔϓϥοτϑΥʔϜ͕ଟ਺ग़ݱ͠·ͨ͠ɻ ฐࣾΠϯϑϥ্Ͱͷඪ४όʔδϣϯ͸

    3.2Ͱ͢ 2012೥ݱࡏɺRoRͷ࠷৽όʔδϣϯ͸ 3.2 Ͱ͢ɻϦϒηϯεࣾ಺Ͱ͸͍ͬͨΜ3.2 Λඪ४ͱͯ͠ઃఆ͠·ͨ͠ɻಛʹཧ ༝͕ͳ͚Ε͹ 3.2 Λಋೖ͍ͯͩ͘͠͞ɻ ͜ͷόʔδϣϯͰ͸ɺσϑΥϧτͰੜ੒͞ΕΔΞϓϦέʔγϣϯʹ͸͍͔ͭ͘ͷಛ௃͕͋Γ·͢ɻ ‣RackΞϓϦέʔγϣϯͱ࣮ͯ͠૷͞Ε·͢ɻଞͷRackϛυϧ΢ΣΞͱ૊Έ߹ΘͤΔ͜ͱ͕ՄೳͰ͢ɻ ‣CSSϑϨʔϜϫʔΫͱͯ͠ Scss ͕࠾༻͞Ε͍ͯ·͢ ‣JavascriptϑϨʔϜϫʔΫͱͯ͠ CoffeeScript ͕࠾༻͞Ε͍ͯ·͢ɻjQuery ΋ࣗಈతʹؚ·Ε·͢ ‣ΞηοτύΠϓϥΠϯʹΑΓɺෳ਺ͷJS΍CSSϑΝΠϧΛ݁߹ͯ͠ग़ྗ͢ΔΑ͏ʹͳ͍ͬͯ·͢ ‣DB؀ڥͱͯ͠ sqlite3 Λར༻͢Δઃఆʹͳ͍ͬͯ·͢ Sqlite3͕σϑΥϧτͰ͕͢ฐࣾ؀ڥͰ͸࢖͑·ͤΜ Կ΋ΦϓγϣϯΛࢦఆ͠ͳ͍৔߹ɺσʔλϕʔεͱͯ͠sqlite3 Λར༻͢Δߏ੒ͰΞϓϦέʔγϣϯ͸ੜ੒͞ΕΔͷ Ͱɺsqlite3 ͕Πϯετʔϧ͞Ε͍ͯͳ͍؀ڥͰ͸࣮ߦͰ͖ͳ͍৔߹͕͋Γ·͢ɻ ޙ͔Β sqlite3 ͔ΒผͷϥΠϒϥϦʢMySQLͳͲʣʹ੾Γସ͑ͯ΋Α͍Ͱ͢͠ɺ࠷ॳ͸DBͳ͠Ͱ։ൃΛ։͍࢝ͨ͠৔ ߹ʢAPIαΠτͳͲʣ͸ rails new ʹ -O ΦϓγϣϯΛ͚ͭΔࣄͰσʔλϕʔε઀ଓ؀ڥͷઃఆΛͤͣʹΞϓϦέʔγϣ ϯΛੜ੒͢Δ͜ͱ͕Ͱ͖·͢ɻ 2012೥3݄ݱࡏɺϦϒηϯεͷαʔό؀ڥʢ։ൃ؀ڥؚΉʣͰ͸ sqlite3 ͸ར༻Ͱ͖·ͤΜɻͦͷͨΊɺ࠷ॳ͔Β MySQL઀ଓΛ४උͯ͠࡞੒͢Δ͔ɺDBͳ͠ͷߏ੒ͰΞϓϦέʔγϣϯ͸ੜ੒͢Δ͜ͱʹͳΓ·͢ɻ # DB࢖༻ͳ͠ rails new NoDBAppSample -O # DBͱͯ͠ MySQLΛར༻͢Δ rails new MySQLAppSample -d mysql RackͱRails Rackͱ͸ WebΞϓϦέʔγϣϯͷ࢓༷ΛఆΊͨ΋ͷͰɺJ2EE΍wsgi ͷΑ͏ͳ΋ͷͰ͢ɻ RailsΞϓϦέʔγϣϯ͸ Rack ΞϓϦέʔγϣϯͱͯ͠࡞੒͞ΕɺRack αʔόͷ্Ͱ࣮ߦ͞Ε·͢ɻ Ruby and Rails ิ଍ Ruby and Rails ิ଍
  11. Rackͷαʔό͸γϯϓϧͰɺೖྗʢRequestʣͱग़ྗʢResponseʣͷΦϒδΣΫτΛఆٛ͠ɺͦͷΦϒδΣΫτΛར ༻ͯ͠ೖग़ྗΛߦ͏ϝιουΛඋ͑ͨΦϒδΣΫτΛʮWebΞϓϦέʔγϣϯʯͱ࣮ͯ͠ߦ͢ΔػೳΛඋ͍͑ͯΔ͚ͩ Ͱ͢ɻೖྗͱग़ྗ͕ܾ·͍ͬͯΔͨΊɺผͷ Rack ΞϓϦέʔγϣϯΛϥοϓ͢ΔϓϩΩγΞϓϦέʔγϣϯΛ༰қʹ ࡞੒Ͱ͖·͢ɻ ͜͏ͨ͠ߏ੒ΛऔΔࣄͰɺΞϓϦέʔγϣϯຊମͷػೳͱ෇ՃతͳػೳΛ෼཭͢Δࣄ͕ग़དྷΔʢผͷΞϓϦέʔγϣ ϯʹػೳΛ෇༩͢ΔΑ͏ͳΞϓϦέʔγϣϯΛϛυϧ΢ΣΞͱݺͼ·͢ʣɺαʔόͷ࣮૷ͱΞϓϦέʔγϣϯͷ࣮૷Λ ੾Γ཭͢͜ͱ͕Ͱ͖Δͱ͍͏ϝϦοτ͕͋Γ·͢ɻ ‣http://rack.rubyforge.org/

    : Rack ެࣜαΠτ ‣http://gihyo.jp/dev/serial/01/ruby/0023 : Rackͱ͸Կ͔ ීஈ͸ؾʹ͢Δඞཁͷແ͍ϛυϧ΢ΣΞ͔ͱࢥ͑͹ɺݱࡏͷόʔδϣϯͷ RoR ΞϓϦέʔγϣϯͰ͸ɺೖग़ྗͷ Request / Response Ϋϥε΍ Session ͳͲͷ࢓૊Έ͸ Rack ͷ΋ͷΛར༻͢ΔͨΊɺΞϓϦέʔγϣϯʹ΋௚઀తʹؔ ܎͖ͯ͠·͢ɻ Rack Λؾʹ͢Δඞཁ͕͋Δྫ : Rack::Resquest ͷ ssl? ͳͲ͸ฐࣾ؀ڥʹ͸ରԠ͠·ͤΜ ฐࣾΠϯϑϥ؀ڥͰ͸ SSL ௨৴࣌ʹ؀ڥม਺ HTTPS ·ͨ͸ HTTP_SSL ͕ઃఆ͞Ε·͢ɻ ͜ΕΒ͸Ұൠతͳʮඪ४ʯͷํ๏ͱ͸ҟͳΔͷͰɺrack ͷ Request#ssl? ͸ඞͣ false Λฦ͠ɺRequest#scheme ͸ඞ ͣ “http://” Λฦ͠·͢ɻͦ͜ͰɺҎԼͷΑ͏ͳରԠΛߦ͍·͢ɻҎԼͷίʔυ͸ٙࣅͰ͢ɻ def Rack::Request.ssl? self.env['HTTPS'].present? || self.env['HTTP_SSL'].present? end Rack Λؾʹ͢Δඞཁ͕͋Δྫ2 : RackͷSession ͸໌ࣔతʹແޮʹͰ͖·ͤΜ Rails 2.x ·Ͱ͸ίϯτϩʔϥͰ໌ࣔతʹ session :off ͱ͢Δ͜ͱ͕Ͱ͖·ͨ͠ɻ Rails 3.x ͔Β͸Rack ͷηογϣϯػߏΛར༻͠·͢ɻͪ͜Β͸஗Ԇϩʔυ͞ΕΔܗʹͳ͍ͬͯͯɺ࠷ॳʹಡΈࠐΜͩ ࡍʹSession ͕෮ݩ͞Ε·͢ɻ·ͨɺ࠷ॳʹॻ͖ࠐΜͩࡍʹൃߦ͞Ε·͢ɻ͕ͨͬͯ͠ɺηογϣϯ࢖͍ͨ͘ͳ͚Ε͹࢖ Θͳ͚Ε͹৽ن࡞੒͸͞Ε·ͤΜɺͱ͍͏͔ͨͪʹͳΓ·͢ɻ ͱ͜Ζ͕ɺform_tag ͳͲͷϑΥʔϜੜ੒ϔϧύʔΛར༻͢ΔࡍɺCSRFରࡦͷτʔΫϯ͕ຒΊࠐ·ΕΔͨΊʹɺηο γϣϯͷಡΈग़͠/ॻ͖ग़͕͠ඞͣ૸ͬͯ͠·͍·͢ɻͦͷଞɺηογϣϯ΁ΞΫηε͢Δ͜ͱ͕ՄೳͳՕॴ͸ଟذʹΘ ͨΔͨΊɺΞΫηεࣗମΛ੍ޚ͢Δ͜ͱ͸ࠔ೉Ͱ͢ɻ ϩϘοτʹରͯ͠ηογϣϯΛൃߦ͠ͳ͍Α͏ʹ͢ΔΞϓϩʔνΛऔΔͨΊʹɺҰ޻෉͕ඞཁͰ͢ɻ Ruby and Rails ิ଍ Ruby and Rails ิ଍
  12. chintai.roomsestate.com Ͱ͸ɺҎԼͷΑ͏ʹͯ͠ίϯτϩʔϥͷॳظԽ࣌ʹڧ੍తʹηογϣϯ෮ݩࡁΈͷϚʔΫΛ ͚ͭɺΞΫγϣϯऴྃޙɺηογϣϯ࢖༻ͳ͠ͱ͢Δ͜ͱͰӬଓԽɾ৽ن࡞੒Λ཈੍͍ͯ͠·͢ɻ͜Ε͸͔ͳΓ࢒೦ͳ ํ๏Ͱ͢ɻ # ηογϣϯΦϒδΣΫτΛ෮ݩࡁΈʹϚʔΫ before_filter do session.instance_variable_set('@loaded', true)

    if is_robot? end # ηογϣϯΦϒδΣΫτΛมߋͳ͠ʹϚʔΫ after_filter do session.instance_variable_set('@loaded', false) if is_robot? end ͜ͷ࣮૷͸ RackͷSessionHash ͷ಺෦࣮૷ʹ׬શʹґଘ͍ͯ͠·͢ɻຊདྷެ։͞Ε͍ͯͳ͍ @loaded Πϯελϯε ม਺Λ֎෦͔Βॻ͖׵͍͑ͯΔͨΊɺRack ͷόʔδϣϯมߋʹΑͬͯಈ࡞͠ͳ͘ͳΔՄೳੑ͕͋Γ·͢ɻ ͜͜Ͱར༻͍ͯ͠Δ is_robot? ϝιου͸ޙड़ͷ php_common_lib ͱڞ௨ͷਖ਼نදݱΛ༻͍࣮ͯ૷͍ͯ͠Δ಺෦ϝ ιουͰ͢ɻ ΞηοτύΠϓϥΠϯͱ CoffeeͱScss CoffeeScript͸ Javascript ʹίϯύΠϧ͞ΕΔܰྔݴޠͰ͢ɻ࣮ߦʹ͸JavascriptϥϯλΠϜ͕ඞཁͰ͢ɻ Ssss͸CSSʹίϯύΠϧ͞ΕΔܰྔݴޠͰ͢ɻʢSASSͷ࢞ຓ඼Ͱ͢ʣ ͜͏͍ͬͨผͷݴޠʹίϯύΠϧ͞Ε࣮ͯߦ͢ΔํࣜΛτϥϯείϯύΠϧͱݴ͏ͦ͏Ͱ͢ɻʢܡ͞Μʣ RoR͸ όʔδϣϯ3͔Βɺ͜ΕΒͷτϥϯείϯύΠϧܗࣜͷهड़ํࣜͱɺίϯύΠϧ͞Εͨෳ਺ͷ CSS / Javascript ίʔυΛ·ͱΊͯ݁߹͠ɺίϯύΫςʔγϣϯʢసૹྔͱϦΫΤετ਺࡟ݮ͕ظ଴Ͱ͖·͢ʣ͢Δͱ͍͏ػೳ͕௥Ճ͞ Ε͍ͯ·͢ɻΞηοτύΠϓϥΠϯͱݺ͹Ε·͢ɻ ‣http://railsdoc.com/asset_pipeline : ΞηοτύΠϓϥΠϯ ‣http://sass-lang.com/ : SCSS ‣http://coffeescript.org/ : CoffeeScript ެࣜαΠτ ‣http://minghai.github.com/library/coffeescript/index.html : CoffeeScript ຊͷ຋༁ ͳ͓ɺCoffee Script΋ Scss ΋ར༻͢Δඞཁ͸ͳ͘ɺͲͪΒ΋Φϓγϣϯѻ͍Ͱ͢ɻͨͩ͠ɺσϑΥϧτߏ੒Ͱ͸Ͳͪ Β΋༗ޮʹͳ͍ͬͯ·͢ɻ Ruby and Rails ิ଍ Ruby and Rails ิ଍
  13. ϓϩμΫγϣϯϞʔυͰಈ࡞ͤ͞Δࡍɺඪ४Ͱ͸ΞηοτύΠϓϥΠϯ͸ಈతίϯύΠϧ͞Ε·ͤΜ Ͳ͏͍͏͜ͱ͔ͱ͍͏ͱɺσϑΥϧτͰ࡞੒ͨ͠௚ޙͷઃఆͩͱɺϓϩμΫγϣϯϞʔυͰΞϓϦέʔγϣϯΛಈ࡞ ͤ͞ΔͱΞηοτύΠϓϥΠϯΛ࢖༻ͯ͠ࢀর͢ΔϑΝΠϧ͕ಡΈࠐΊͳ͍ͱ͍͏͜ͱͰ͢ɻ ΞηοτύΠϓϥΠϯΛར༻ͨ͠ΞϓϦέʔγϣϯͰ͸ෳ਺ͷ CSS ΍ Javascript ϑΝΠϧ͕ίϯύΠϧɾ݁߹͞Εͯ ҰͭͷϑΝΠϧͱͯ͠ར༻͞Ε·͢ɻ ͦͷࡍɺϑΝΠϧ໊͸ϋογϡΛར༻ͨࣗ͠ಈతʹ෇༩͞ΕΔ΋ͷ͕࢖ΘΕ·͢ɻ

    ϑΝΠϧ໊Λੜ੒͢Δϔϧύʔʢlink_toɺ image_tag ɺ style_tag ͳͲʣͰ͸ͦΕ͕ߟྀ͞Εʮਖ਼͍͠ʯϑΝΠϧ໊Ͱ ϦϯΫ͢Δλά͕ੜ੒͞Ε·͢ɻ͔͠͠ɺσϑΥϧτͷઃఆͰ͸ಈతͳίϯύΠϧ͕ߦΘΕͳ͍ͨΊɺʮਖ਼͍͠ʯϑΝ Πϧ໊ͰΞΫηε͞ΕΔର৅ͷ݁߹͞ΕͨϑΝΠϧ͸ଘࡏ͠·ͤΜɻ ରࡦͱͯ͠͸ɺʮಈతίϯύΠϧΦϓγϣϯΛ༗ޮʹ͢Δʯ͔ʮϓϦίϯύΠϧΛߦ͏ʯ͜ͱʹͳΓ·͢ɻ ಈతίϯύΠϧΦϓγϣϯΛઃఆ͢Δʹ͸ɺҎԼͷΑ͏ʹ͠·͢ɻ # config/environments/production.rb config.assets.compress = true ϓϦίϯύΠϧΛߦ͏৔߹͸ rake Λ༻͍ͯҎԼͷΑ͏ʹ͠·͢ɻ $ bundle exec rake assets:precompile RAILS_ENV=production ͜ͷίϚϯυͰ͸ϓϦίϯύΠϧࡁΈͷϑΝΠϧ͕ public/assets/ ҎԼʹ࡞੒͞Ε·͢ɻ ಈతίϯύΠϧΛߦ͏ͨΊʹ͸αʔό͔ΞϓϦέʔγϣϯͰ Javascript ͷ࣮ߦܥΛ༻ҙ͢Δඞཁ͕͋Γ·͢ɻnode.js ͱ͔ therubyrhino (࠷ॳಡΊ·ͤΜɻThe Ruby RhinoͰ͢Ͷ)ͳͲ͕αϙʔτ͞Ε͍ͯ·͢ɻ΋ͪΖΜϓϦίϯύΠϧΛ ߦ͏ํ͕ύϑΥʔϚϯε্͸༗རͰ͕͢ɺසൟʹߋ৽͞ΕΔڊେͳϑΝΠϧ͕͋ΔͷͰ΋ͳ͍ݶΓɺίϯύΠϧࡁΈͷ ϑΝΠϧ͸Ωϟογϡ͞ΕΔͷͰ໰୊͸ൃੜ͠ͳ͍ͱࢥ͍·͢ɻ RoR 3 Ͱ͸ετϦʔϛϯάରԠͯ͠·͢ ετϦʔϛϯά͸ͦͷ໊ͷ௨ΓɺͰ͖ͨͱ͜Ζ͔Βग़ྗ͢ΔํࣜͰ͢ɻετϦʔϛϯάͱ͍͏ͱಈը͹͔Γ͕औΓ্ ͛ΒΕ·͕͢ɺϨϯμϦϯάʹ࣌ؒͷ͔͔ΔHTMLίϯςϯπͷఏڙʹ΋े෼༗ޮͰ͢ɻRoRͰ͸ͳ͍Ͱ͕͢ɺ༗໊ͳ ͱ͜ΖͰ͸Facebook ͷύϑΥʔϚϯε࠷దԽઓུʹ࢖ΘΕ͍ͯ·͢ɻ ‣http://www.infoq.com/jp/news/2010/07/bigpipe-facebook-optimize : FacebookͷBigPipe: ϖʔδϩʔυ࣌ؒͷ࠷దԽ ΋ͪΖΜɺ͜ͷํࣜΛऔΖ͏ͱ͢ΔͱʮϨϯμϦϯά݁Ռʹରͯ͠શஔ׵ʯͳͲͷϑΟϧλ͕࢖͍ਏ͘ͳΓ·͢ɻίϯ ςϯπΛ෦෼෦෼ͱͯ͠ಠཱͯ͠ϨϯμϦϯάɾϑΟϧλॲཧ·ͰͰ͖ΔΑ͏ʹ্ͨ͠Ͱͳ͍ͱ೉͍͠ͱࢥ͍·͢ɻ΋ͪ Ruby and Rails ิ଍ Ruby and Rails ิ଍
  14. ΖΜɺετϦʔϛϯά͠ͳ͍ͱόΧʹͳΒͳ͍ίϯςϯπྔʹͳΔͷͰ͋Ε͹ɺ͜͜·Ͱͷ࠷దԽ΋ׂʹ߹Θͳ͍΋ͷ Ͱ͸ͳ͍Ͱ͠ΐ͏͕ɻ Ұ೥લͷ࣌఺Ͱ͸๭RఱࣾͰ͸͜ͷΑ͏ͳ࠷దԽ͸ͱΓ͋͑ͣߦΘΕ͍ͯ·ͤΜͰͨ͠ɻ๭ࣾαΠτ͸ίϯςϯπͷϨ ϯμϦϯάΑΓ΋ը૾਺΍Β javascriptʹΑΔ௨৴͕େྔʹͳΔ͜ͱʹΑΓɺηογϣϯ਺͕૿͑Δ͜ͱͷํ͕ΫϦςΟ ΧϧͩͬͨΑ͏ͰɺόΧߴ͍CDSΛར༻͢Δ͜ͱͰτϥϑΟοΫΛ͞͹͍͍ͯ·ͨ͠ɻWebαΠτͷύϑΥʔϚϯεϘ τϧωοΫ͕Ͳ͜ʹ͋Δ͔͸೉͍͠໰୊Ͱ͢ɻ ౰໘ɺHTMLͷϨϯμϦϯάύϑΥʔϚϯε͕໰୊Ͱ͋ΓɺͦͷݪҼ͕୯Ұ΋͘͠͸͘͝গ਺ͷڊେͳSQLΫΤϦͰ ͸ͳ͍ͱΘ͔͍ͬͯͯɺը໘͕ෳ਺ͷಠཱͨ͠ྖҬʹ෼ׂՄೳͰ͋Δ͜ͱ͕Θ͔͍ͬͯΔ৔߹͘Β͍͔͜͠͏͍ͬͨύ ϑΥʔϚϯεվળࡦΛऔΔඞཁ͸ͳ͍Ͱ͠Α͏ɻ

    WebSocket ͱ௨৴͢ΔɾComet αʔόΛ࣮૷͢Δ৔߹ɺݕ౼ͯ͠΋໘ന͍ͱࢥ͍·͢ɻ ࠾༻࣮੷ Ձ֨.comɺΫοΫύουɺ৯΂ϩάͳͲେख͕ࠃ಺Ͱ΋࠾༻͍ͯ͠·͢ɻ େن໛αΠτͷ࠾༻ࣄྫ͸૿͖͍͑ͯͯ·͢ɻTwitter͕౰ॳ Rails Ͱӡ༻͞Ε͍ͯͨͷ͸༗໊ͳ࿩Ͱ͕͢ɺύϑΥʔ Ϛϯεͷ໰୊͔Βॻ͖׵͑ΒΕͨͷ΋༗໊Ͱ͢ɻ Redmine ͳͲ͸ Ruby Ͱಈ࡞͍ͯ͠·͢ɻ ࣾ಺Ͱ͸͍͔ͭ͘ͷখن໛ͳαΠτͰར༻͞Ε͍ͯ·͢ɻ Rails ͷ৘ใࢀরઌ ‣http://rubyonrails.org/ : Rails ެࣜαΠτ ‣http://guides.rubyonrails.org/ : Ruby on Rails Guides ‣http://asciicasts.com/ : ASCII casts (http://ja.asciicasts.com/ ೔ຊޠ༁൛) ։ൃ؀ڥͳͲ΋Ζ΋Ζ Use NetBeans ແྉͷπʔϧͷதͰ͸ແ೉ͳͷ͸NetBeans͔ͱࢥ͍·͢ɻMac؀ڥɺLinuxσεΫτοϓ ɺWindowsͦΕͧΕͰಈ࡞͠ ·͢ɻEclipse ϕʔεͷ΋ͷ΋͍Ζ͍Ζ͋ΔΑ͏Ͱ͕͢ɺͪ͜Β͸ະ֬ೝͰ͢ɻ ࠷৽ͷ NetBeans 7.1 Ͱ͸ RoR ։ൃΛެࣜʹ͸αϙʔτ͍ͯ͠·ͤΜ͕ɺϓϥάΠϯΛಋೖ͢Δ͜ͱͰରԠՄೳͰ ͢ɻ Ruby and Rails ิ଍ Ruby and Rails ิ଍
  15. ‣http://plugins.netbeans.org/plugin/38549/ruby-and-rails : NetBeans Plugin ‣http://blog.enebo.com/2012/01/workaround-for-ruby-support-on-netbeans.html : for 7.1 workaround. ͚ͨͧ͏͞Μ͕঺հ͍ͯ͠Δ

    RoRED ͳͲ΋Α͍͔΋͠Ε·ͤΜɻͪ͜Β͸Windows޲͚Ͱ͢ɻ൚༻Ͱ͸ͳ͘ RoRಛ Խܕɺγϯϓϧࢦ޲ͳͷͰ࢖͍΍͍͢Մೳੑ͸͋Γ·͢ɻ ‣http://news.mynavi.jp/column/ide/058/index.html : Rails޲͚ͷWindows༻ܰྔIDEʮRoREDʯΛࢼͯ͠ΈΔ ͨͩɺޙड़ͷ௨Γ Windows؀ڥ͸͋·ΓΦεεϝͰ͖·ͤΜɻ Windows؀ڥͰ͸͋·ΓΑ͍։ൃ؀ڥ͕࡞Ε·ͤΜ ࢒೦ͳ͕ΒɺWindows؀ڥͰ͸ Ruby ୯ମͰ͸ಈ࡞ͯ͠΋ؔ࿈͢ΔϥΠϒϥϦ܈͕׬શʹ͸ಈ࡞͠ͳ͍͜ͱ͕ଟ͍Ͱ ͢ɻಛʹαʔόܥͷϞδϡʔϧ͸ΫϦςΟΧϧͳ΋ͷ͕ಈ͔ͳ͍Α͏Ͱ͢ɻͨͱ͑͹ɺMySQLͷಛఆͷόʔδϣϯͩͱ υϥΠό͕࢖͑ͳ͍ͱ͔ɺiconv ͳͲͷؔ࿈ϥΠϒϥϦ΋શͯखಈͰઃఆ͢Δඞཁ͕͋Δͱ͔ɻ Windowsʹͩ͜ΘΔཧ༝͕ͳ͚Ε͹ɺVMWare ͳͲΛར༻ͯ͠ Linux ؀ڥʹ։ൃ؀ڥΛߏங͢Δํ͕؆୯Ͱ͢ɻ Ruby on Rails ͸ Git Ͱ ผʹܾ·͍ͬͯΔΘ͚Ͱ͸ͳ͍Ͱ͕͢ɺRails ΞϓϦέʔγϣϯΛੜ੒͢Δͱ git ༻ͷແࢹϑΝΠϧϦετͳͲ͕ࣗಈ తʹੜ੒͞Ε·͢ɻRuby ͷϥΠϒϥϦηοτͰ͋Δ Gem ΋৽͘͠࡞Δͱࣗಈతʹ GitHub ޲͚ͷઃఆΛ༻ҙ͍ͯͨ͠ Γ͢ΔͷͰɺશମతʹ Git Ͱ΍Γ·͠ΐ͏ͱ͍͏งғؾ͕͋Γ·͢ɻ Ϧϒηϯεࣾ಺Ͱ΋ Git Ͱ؅ཧ͢Δงғؾ͕ڧ͍ͷͰɺRuby ΞϓϦέʔγϣϯΛ৽͘͠࡞ΔͷͰ͋Ε͹ Git Ϧϙδτ ϦΛར༻͢Δ͜ͱʹͳΔͰ͠ΐ͏ɻ ‣http://vms-svn.office.livesense.jp/git/ : ࣾ಺ git ϦϙδτϦ ςεςΟϯάϑϨʔϜϫʔΫ͕ॆ࣮͍ͯ͠·͢ ୯ମςετϑϨʔϫʔΫͰ͸ Ruby ඪ४ͷtest-unit ɺϏϔΠϏΞۦಈ։ൃͷੈքͰ༗໊ʹͳͬͨ४ͰϑΝΫτελϯ μʔυͷ RSpec ͳͲ͕͋Γ·͢ɻʮड͚ೖΕςετʯΛλʔήοτʹͨ͠ऴ୺࢓༷Λهड़͢ΔCucumber ͳͲ΋༗໊Ͱ ͢ɻςετۀքͰ͸ Ruby ͸ϗοτͳྖ෼Ͱ͢ɻ ‣http://www.oiax.jp/rails/zakkan/test_frameworks_for_rails_3_x_era_ii.html : ଓɾRails 3.x ࣌୅ͷςετϑϨʔϜϫʔΫ Ruby ͷςετϑΝʔετ։ൃʹ͍ͭͯ͸ผࢿྉʹৡΓ·͢ɻ͖ͬͱԘ଍͞Μ͕ॻ͍ͯ͘ΕΔͰ͠ΐ͏ɻ ςεςΟϯάͱ͍͏Θ͚Ͱ͸ͳ͍Ͱ͕͢ɺRuby ඪ४ͷ Benchmark ϞδϡʔϧΛར༻͢Δ͜ͱͰ࣮ߦ࣌ؒΛ༰қʹଌ Δࣄ͕ग़དྷ·͢ɻ Ruby and Rails ิ଍ Ruby and Rails ิ଍
  16. ‣http://doc.ruby-lang.org/ja/1.9.2/library/benchmark.html : benchmarkϞδϡʔϧ Ruby ͷϓϩάϥϜ΍ϥΠϒϥϦ͸ ύοέʔδ؅ཧπʔϧ RubyGems Ͱ؅ཧ͞Ε͍ͯ·͢ RubyGems ͸ʮRuby

    ϓϩάϥϜ΍ϥΠϒϥϦͷ؅ཧπʔϧɺ·ͨ͸഑෍༻ͷΞʔΧΠϒܗࣜʯͰ͢ɻPHPͷPEARɺ Debian ͷ APT ͷΑ͏ͳ΋ͷͰ͢ɻ RubyGems ͕Πϯετʔϧ͞Ε͍ͯΔγεςϜͰ͋Ε͹ɺ rails ͷΠϯετʔϧ͸ҎԼͷҰߦͷίϚϯυ࣮ߦͰ׬ྃ͠ ·͢ɻ $ gems install rails Ruby ͷ σόοΨ΍ Web αʔόɺ Rails ͷ֦ுػೳͳͲ͸΄ͱΜͲͷ৔߹ Gem ͷܗࣜͰఏڙ͞Ε͍ͯ·͢ɻ Gemͱ͍͏໊લ͸ఏڙ͞ΕΔϥΠϒϥϦͷ഑෍୯ҐͰ͋ΔଞɺΠϯετʔϧ͞Ε͍ͯΔϥΠϒϥϦͷ୯Ґͱͯ͠΋࢖ ΘΕ·͢ɻGemʹ͸ґଘؔ܎͕͋Γɺgem install Ͱ͸ґଘ͢Δ gem ΋ಉ࣌ʹΠϯετʔϧ͞ΕΔ͜ͱ͕ී௨Ͱ͢ɻgem ʹ͸ϐϡΞͳruby Ͱॻ͔Ε͍ͯΔ΋ͷͱɺωΠςΟϒ࣮૷Λඞཁͱ͢Δ΋ͷ͕͋ΓɺωΠςΟϒ࣮૷Λඞཁͱ͢Δ gem ͸Πϯετʔϧ࣌ʹϩʔΧϧͰϏϧυ͞Ε·͢ɻͦͷࡍɺඞཁͱ͢ΔϥΠϒϥϦ͕؀ڥʹଘࡏ͠ͳ͚Ε͹Ϗϧυࣦഊͱ ͳΓɺgemͷΠϯετʔϧ΋Ͱ͖·ͤΜͷͰ஫ҙ͍ͯͩ͘͠͞ɻ ޙड़ͷ rvm ΍ rails ຊମ΋ruby gem Ͱ؅ཧɾΠϯετʔϧͰ͖ΔͷͰɺ·ͣ RubyGems Λ؀ڥʹઃఆ͢Δͱ͜Ζ͔ Β࢝ΊΔͱΑ͍ͱࢥ͍·͢ɻ ৄࡉ͸ҎԼαΠτΛࢀর͍ͯͩ͘͠͞ɻ ‣http://ja.wikipedia.org/wiki/RubyGems ‣http://rubygems.org/ ‣http://d.hatena.ne.jp/gtaka555/20071012/p3 (Windows) ෳ਺ͷRuby ؀ڥʢόʔδϣϯҧ͍΍Πϯετʔϧ͢Δ Gem ͷ੾Γସ͑ͳͲʣΛӡ༻͢Δ rvm/pik ݱࡏͷ࠷৽ͷ ruby ϥϯλΠϜ͸ 1.9.3Ͱ͢ɻruby ͷ gem ͸ಛఆͷόʔδϣϯʹͷΈରԠͨ͠΋ͷ͕਺ଟ͋͘Γ·͢ɻ ·ͨɺRails ΋ಛఆͷ Rubyͷόʔδϣϯͱͷ૊Έ߹ΘͤͰ໰୊͕͋ͬͨΓ͠·͢ɻ γεςϜશମʹ͏͔ͬΓαʔόͰ͸ಈ࡞ͤ͞ΒΕͳ͍ gem ΛΠϯετʔϧͯ͠͠·͍ɺ։ൃ؀ڥͰ͸࣮ߦͰ͖Δ͕࣮ ؀ڥͰ͸ಈ࡞͠ͳ͍ϓϩάϥϜʹͳͬͯ͠·͏͜ͱ΋͋Γ·͢ɻ ͦ͜ͰɺRuby ͷϥϯλΠϜ؀ڥΛ੾Γସ͑Δπʔϧ͕ඞཁͰ͢ɻpython Ͱ͍͏ virtualenv ͷΑ͏ͳ΋ͷͰ͕͢ɺrvm ͷํ͕໢ཏతʹศརͰ͢ɻpik ͸ ࣅͨΑ͏ͳػೳΛ Windows؀ڥͰ࣮ݱ͢Δ΋ͷͰ͢ɻ ‣http://beginrescueend.com/ : rvmެࣜϖʔδ ‣http://d.hatena.ne.jp/holypp/20110407/1302193459 : Rubyͷෳ਺όʔδϣϯΛڞଘͤ͞Δgemɻrvmͱpikʹ͍ͭͯ ‣https://github.com/vertiginous/pik : pik ϓϩδΣΫτϖʔδ Ruby and Rails ิ଍ Ruby and Rails ิ଍
  17. ͍ͭͰʹ༗༻ͳϥΠϒϥϦɾখωλ jpmobile : ೔ຊͷΨϥέʔରԠ ೔ຊͷܞଳ୺຤ରԠػೳΛ Rails ΞϓϦέʔγϣϯʹ௥Ճ͢ΔΦʔϓϯιʔεϥΠϒϥϦͰ͢ɻϥΠηϯε͸MITͷͨ ΊɺϓϩμΫτ಺Ͱࣗ༝ʹར༻ՄೳͰ͢ɻ Rails 2.x

    ·Ͱ͸ϓϥάΠϯͷܗࣜͰఏڙ͞Ε͍ͯ·͕ͨ͠ɺRails 3.x ͔Β͸ϓϥάΠϯ͕ඇਪ঑ʹͳͬͨͨΊɺ RubyGemsͱͯ͠Πϯετʔϧ͢Δܗࣜʹมߋ͞Ε·ͨ͠ɻ େ·͔ʹɺҎԼͷΑ͏ͳػೳ͕͋Γ·͢ɻ ‣ܞଳ୺຤ͷػछͷ൑ఆɺIPϨϯδͷ൑ఆʢIPϨϯδߟྀ͸௥ՃϥΠϒϥϦΛηοτͰಋೖ͢Δඞཁ͕͋Γ·͢ʣ ‣ܞଳ୺຤ͷ୺຤IDͷऔಘ ‣DoCoMoͳͲʹର͢Δࣗಈతͳ mime-type ͷมߋ(SJIS / xhtml) ‣ֆจࣈͷΩϟϦΞؒͷม׵ ‣ηογϣϯIDͷURL΁ͷ෇༩ / URL͔Βͷऔಘ ‣ϞόΠϧ / PCͰͷϏϡʔςϯϓϨʔτͷ੾Γସ͑ ࠃ಺ͷέʔλΠαΠτ։ൃͰ͸΄΅σϑΝΫτελϯμʔυʹͳ͍ͬͯΔΑ͏Ͱ͢ɻ gem ίϚϯυͰΠϯετʔϧ͢Δ͜ͱ͕Ͱ͖·͢ɻ ‣http://jpmobile-rails.org/ : jpmobile ެࣜαΠτ ‣http://subtech.g.hatena.ne.jp/secondlife/20110315/1300190684 :Rails 3 + jpmobile Λಈ͔͢ jpmobile ͷηογϣϯIDͷURLͷ෇༩͸ػछ୯ҐͰ൑ఆ͞Ε·͢ ಺෦Ͱ Cookie Λอ࣋Մೳͳ୺຤͔Ͳ͏͔ͷσʔλΛ͓࣋ͬͯΓɺ൑ఆ࣌ʹ Cookie ࢖༻ෆՄೳͳ୺຤ʹରͯ͠ͷΈɺ ηογϣϯIDͷURLύϥϝʔλ΁ͷม׵Λߦ͍·͢ɻ͔͠͠ɺ͜Ε͸ػछͷσϑΥϧτઃఆͰʮCookieΛૹ৴͠ͳ͍ʯ ʹͳ͍ͬͯͨΓ͢Δ͜ͱΛ૝ఆ͍ͯ͠·ͤΜɻ·ͨɺi-mode ϒϥ΢β͕ Cookie ඇରԠͰ͋ͬͯ΋ɺCookie ࢖༻Մೳͳ ϑϧϒϥ΢βΛ౥ࡌ͍ͯ͠ΔػछͰ͋Δ৔߹ʹ͸ɺCookieରԠ୺຤ͱͯ͠ॲཧ͞ΕΔΑ͏Ͱ͢ɻ શͯͷ୺຤Λ Cookie ඇରԠͱͯ͠URLύϥϝʔλΛར༻ͨ͠ ηογϣϯID؅ཧʹ͢ΔͨΊʹ͸ɺjpmobile ͷ Cookie ༗ޮ൑ఆΛ্ॻ͖ͯ͠͠·͏ͷ͕Ұ൪༰қͰ͢ɻ Ruby and Rails ิ଍ࢿྉ Ruby and Rails ิ଍ࢿྉ
  18. ྫ͑͹ɺίϯτϩʔϥͰҎԼͷΑ͏ʹϑΟϧλͰ Mobile ΦϒδΣΫτͷ supports_cookie? ϝιουʹϞϯΩʔύο νΛ͋ͯ·͢ɻ before_filter :mobile_cookie_disable_filter, :except =>

    :ga # શͯͷػछͰ cookie support ͕ false ͱͳΔ def mobile_cookie_disable_filter request.mobile? && begin mob = request.mobile def mob.supports_cookie? false end end end jpmobile ͷֆจࣈม׵͸͋͘·Ͱ΋ΨϥέʔͷΩϟϦΞؒม׵ ͔֬ iPhone ͳͲʹ΋ରԠ͍ͯ͠·ͤΜɻ ฐࣾͰར༻͍ͯ͠ΔPHPͷֆจࣈม׵ϥΠϒϥϦͷ {d1124} ͱ͍ͬͨܗࣜʹ͸΋ͪΖΜޓ׵ੑ͸͋Γ·ͤΜɻ ͦ͜Ͱɺchintai.roomsestate.com Ͱ͸ _php_common_lib/LVS/Mobile/ ͔Βม׵ςʔϒϧΛٯى͜͢͠Δͱ͍͏ํ๏ ΛऔΓɺΞΫγϣϯ࣮ߦޙͷ after_filter Ͱ͍ͬͨΜ unicode ֆจࣈʹจࣈྻஔ׵͢Δํ๏ΛऔΓ·ͨ͠ɻ jpmobile ͷ unicode ֆจࣈɹ→ɹ֤ΩϟϦΞؒͷม׵ͱ߹Θͤɺ2ճશஔ׵͕ൃੜ͢ΔܗͰ͕͢ɺม׵ॲཧͦͷ΋ͷ ͕ωοΫʹͳΔέʔε͸ࠓͷͱ͜Ζग़͍ͯ·ͤΜɻ ҎԼɺ໛ࣜతʹॲཧͷྲྀΕΛࣔ͠·͢ɻ Ruby and Rails ิ଍ Ruby and Rails ิ଍
  19. HTML ϨϯμϦϯά unicode ֆจࣈʹม׵ ΩϟϦΞຖͷ ɹֆจࣈʹม׵ After Filter ΞΫγϣϯ ࣮ߦ

    jpmobile ΩϟϦΞຖ ɹจࣈίʔυม׵ CSSͷ ΠϯϥΠϯԽ TamTam Rails ͷ Filter ͸௥Ճͨ͠ॱʹܧঝؔ܎Ͱ࣮ߦॱ͕ܾ·ΔͨΊɺ͜ͷΑ͏ʹґଘؔ܎͕͋ΔϑΟϧλͷઃఆʹ͸஫ҙ͕ ඞཁͰ͢ɻBefore Filter Ͱ͸ઌʹઃఆͨ͠ϑΟϧλͷํ͕ઌʹ࣮ߦ͞Ε·͢ɻAfter Filter͸ͦͷٯͰɺઌʹઃఆͨ͠ ϑΟϧλ͕ޙʹ࣮ߦ͞Ε·͢ɻ jpmobile ͷֆจࣈม׵͸਌ίϯτϩʔϥΫϥεͰ trans_sid ΫϥεϝιουΛݺͼग़ͨ͠ࡍʹઃఆ͞ΕΔͷͰɺࢠ ίϯτϩʔϥΫϥεͷ after_filter ΑΓ΋֎ଆʢޙʣͰ͢ɻjpmobile ʹݶΒͣɺϓϥάΠϯ΍ϥΠϒϥϦͳͲͰΞΫγϣ ϯͷ֎ଆʹॲཧΛ௥Ճ͢Δ৔߹ɺ࣮ߦλΠϛϯά͕ΞϓϦέʔγϣϯͰઃఆ͍ͯ͠ΔݸผͷϑΟϧλͱ૝ఆ֎ʹલޙ͠ ͳ͍͔೺Ѳ͍ͯ͠Δඞཁ͕͋Γ·͢ɻ ‣http://guides.rubyonrails.org/action_controller_overview.html#filters : RailsGuides / Filters jpmobile Λ༗ޮʹ͢ΔͨΊͷઃఆΛ initializer ʹॻ͘ Rails 3.x ͔ΒϓϥάΠϯ͕ඇਪ঑ʹͳͬͨͷͰɺjpmobile ΋ GemͷܗͰར༻͢ΔΑ͏ʹͳ͍ͬͯ·͢ɻRubyGems ͸൚༻తͳϥΠϒϥϦ୯ҐͷͨΊɺݸผͷػೳΛ༗ޮʹ͢Δʹ͸໌ࣔతʹಡΈࠐΉඞཁ͕͋Γ·͢ɻ Rails Ͱ͸ݸผͷϥΠϒϥϦͷॳظԽͳͲͷίʔυ͸ɺconfig/initializers ʹهड़͢Δ͜ͱʹͳ͍ͬͯ·͢ɻ chintai.roomsestate.com Ͱ͸ jpmobile_generator.rb ͱ͍͏ϑΝΠϧΛͦ͜ʹ࡞੒͠ɺҎԼͷίʔυΛஔ͍͍ͯ·͢ɻ require 'jpmobile' ChintaiRoomsestateCom::Application.config.jpmobile.mobile_filter ChintaiRoomsestateCom::Application.config.jpmobile.form_accept_charset_conversion = true tamtam : CSS ΠϯϥΠϯԽ CSSͷΠϯϥΠϯԽͷϥΠϒϥϦɻ ݹ͍ DoCoMo ୺຤౳Ͱ͸֎෦CSS͕ಡΈࠐΊͣɺΠϯϥΠϯԽͷඞཁ͕͋Γ·͢ɻҙ֎ͱΑ͍ํ๏͕ͳ͘ɺ͍Ζ͍Ζ ୳ͨ݁͠Ռ͜ͷͷϥΠϒϥϦΛར༻͍ͯ͠·͢ɻ gem ίϚϯυͰΠϯετʔϧ͢Δ͜ͱ͕Ͱ͖·͢ɻ Ruby and Rails ิ଍ Ruby and Rails ิ଍
  20. CSSΛจࣈྻͰಡΈࠐΈɺจࣈྻʹର͢Δஔ׵ૢ࡞ͱͯ͠ಇ͘ͷͰɺ΍΍บ͕͋Γ·͢ɻchintai.roomsestate.com Ͱ ͸ΞΫγϣϯ࣮ߦޙͷ After Filter ͰϨεϙϯεจࣈྻશମʹର͢Δஔ׵Λߦ͍ͬͯ·͢ɻ΋ͱ΋ͱ͸ςϯϓϨʔτϑΝ Πϧʹର͢ΔલॲཧΛߦ͏༧ఆͰ͕ͨ͠ɺಈతੜ੒Λߦ͏Օॴ΋ଟ͔ͬͨͨΊɺ࠷ऴతͳग़ྗʹର͢Δશஔ׵Λߦ͏Α ͏ʹ͍ͯ͠·͢ɻ CSSͷΩϟογϡॲཧͳͲ͸ল͍͍ͯ·͕͢ɺҎԼͷΑ͏ͳॲཧʹ͍ͯ͠·͢ɻ #

    ϞόΠϧCSSΛΠϯϥΠϯԽ͢ΔϑΟϧλɻ def mobile_css_inline_filter if request.mobile? css = open("#{Rails.root.to_s}/app/assets/stylesheets/mobile.css").read response.body = TamTam.inline :css => css.dup, :body => response.body end end ‣http://tamtam.rubyforge.org/ : ެࣜαΠτ Dalli : Memcached ΫϥΠΞϯτ Memcache ΫϥΠΞϯτϥΠϒϥϦͰ͢ɻ όΠφϦϞʔυͰ௨৴ͯ͘͠ΕΔͷͰ҆શͰ͢ɻશͯ Ruby Ͱॻ͔Ε͍ͯΔͷͰϙʔλϏϦςΟʹ༏Ε͍ͯ·͢ɻϓϩ δΣΫτϖʔδͷઆ໌ʹ Rails 3.x Ͱͷར༻ํ๏͕هड़͞Ε͍ͯΔͷͰదٓࢀর͍ͯͩ͘͠͞ɻ gem ίϚϯυͰΠϯετʔϧ͢Δ͜ͱ͕Ͱ͖·͢ɻ ηογϣϯΛ Dalli Λ༻͍ͯ memcached ʹߏ੒͢Δʹ͸ɺconfig/initializer/session_store.rb ʹҎԼͷΑ͏ʹࢦఆ͠ ·͢ɻcookie_only Λ false ʹࢦఆ͍ͯ͠Δͷ͸ɺjpmobile ͷηογϣϯIDͷURLύϥϝʔλͰͷ࣋ͪճΓػೳରԠͷ ͨΊͰ͢ɻ session_options ΛΧελϚΠζ͢Δ͜ͱͰɺηογϣϯλΠϜΞ΢τ஋ͳͲΛఆٛ͢Δ͜ͱ͕Ͱ͖·͢ɻ # ηογϣϯετΞΛ dalli_store ʹࢦఆ require 'action_dispatch/middleware/session/dalli_store' ChintaiRoomsestateCom::Application.config.session_store :dalli_store ChintaiRoomsestateCom::Application.config.session_options = {:cookie_only => false} ͦͷଞɺηογϣϯ͚ͩͰͳ͘ Rails ͷΩϟογϡػߏͷσʔλετΞʹ Dalli Store Λࢦఆ͢Δ͜ͱ΋Ͱ͖·͢ɻৄ ࡉ͸ϓϩδΣΫτϖʔδͷ Readme ʹهड़͞Ε͍ͯΔͷͰɺࢀর͍ͯͩ͘͠͞ɻ ‣https://github.com/mperham/dalli : ϓϩδΣΫτϖʔδ Ruby and Rails ิ଍ Ruby and Rails ิ଍
  21. ϩϘοτରԠ ϥΠϒϥϦͰ͸ͳ͍Ͱ͕͢ɺ٢ా͞Μ͕தֶੜͷࠒʹॻ͍ͨਖ਼نදݱΛआ༻͍ͯ͠·͢ɻಛʹվม͍ͯ͠·ͤΜɻ ΦϦδφϧ͸ _php_common_lib/LVS/Mobile.php ʹ͋Δ΋ͷͰ͢ɻ ҎԼʹࣔ͢Α͏ͳϞδϡʔϧΛ༻ҙ͍ͯ͠·͢ɻ ͳ͓ɺLvsLib͸౰ॳϓϥάΠϯͱͯ͠࡞੒͍ͯͨ͠΋ͷͰ͕͢ɺ·ͩڞ௨Խ͞Ε͍ͯ·ͤΜɻ module LvsLib module

    RobotsSupport PC_ROBOT= ..লུ MOBILE_ROBOT= .. লུ def self.is_robot_user_agent(user_agent = nil) user_agent ||= ENV["HTTP_USER_AGENT"] user_agent.blank? || MOBILE_ROBOT.match(user_agent) || PC_ROBOT.match(user_agent) end end end ϧʔτఆٛʹ noindex ͱ͔ mobile_only ͱ͔ϑϥάΛؚΊΔ ·ͩʮಈ͍ͨʯϨϕϧͳͷͰɺ໰୊఺ͷࢦఠΛ׻ܴ͠·͢ɻ ฐࣾͰ͸Α͘ʮ͜ͷϖʔδ͸SEOޮՌΛ͍͔͋͛ͨΒʯʮ͜͜ͱ͜͜ʹ͸༠ಋͨ͘͠ͳ͍ɻnoindexΛࢦఆ͢Δʯ ʮಈతURLʹ͸ nofollow Λ͚ͭΔɻͨͩ͜͠ͷ৔߹͚ͩ͸ผʯͱ͍ͬͨࢦఆ͕ԣஅతʹൃੜ͠·͢ɻ ͦ͏͍ͬͨࢦఆΛ΋ͬͱ΋Α͘൓өͰ͖Δͷ͸ؒҧ͍ͳ͘ϧʔτఆٛͰ͢ɻٯʹը໘୯ҐɺΞΫγϣϯ୯ҐͰ΍Ζ͏ ͱ͢Δͱඇৗʹ൥ࡶʹͳΓ·͢ɻURLύλʔϯͱϑϥάΛ؅ཧ͢ΔσʔλϕʔεʢRDBͱ͍͏ҙຯͰ͸ͳ͘ʣΛ࣋ͬͯ ͠·͏ͱ͍͏ख΋͋Γ·͕͢ɺ΍΍൥ࡶͰ͢͠ɺURLύλʔϯͷ؅ཧ͕ଟॏ؅ཧʹͳΓ·͢ɻ ͦ͜Ͱɺϧʔτఆٛʹͦ͏ͨ͠ noindex ͱ͔ moblie_only ͱ͍ͬͨϝλσʔλΛઃఆ͠ɺͦΕΛར༻ͯࣗ͠ಈతʹ੍ ޚΛߦ͏࢓૊ΈΛߟ͑·ͨ͠ɻ ·ͣɺRails.application.routes.recognize_path Λར༻͢Δ͜ͱͰɺURL͔Β URLΦϓγϣϯΛϋογϡͰऔಘ͢Δ͜ ͱ͕Ͱ͖·͢ɻ $ Rails c 1.9.1 :001 > Rails.application.routes.recognize_path("/info/company.htm") => {:action=>"company", :nofollow=>true, :mobile_only=>true, :controller=>"frontend/ info"} Ruby and Rails ิ଍ Ruby and Rails ิ଍
  22. ͜ͷ৔߹ɺinfo/company.htm ͱ͍͏ύεʹ͸ frontend/info ίϯτϩʔϥͷ company ΞΫγϣϯʹؔ࿈෇͚ΒΕ͍ͯ ͯɺnofollow Φϓγϣϯͱ mobile_only Φϓγϣϯ͕ઃఆ͞Ε͍ͯΔ͜ͱ͕Θ͔Γ·͢ɻ

    ϧʔτఆٛͷ֘౰Օॴ͸ҎԼͷΑ͏ͳهड़Ͱ͢ɻ # config/routes.rb ChintaiRoomsestateCom::Application.routes.draw do scope :module => :frontend do .. ུ namespace :info do get "company.htm", { ! ! :action=>:company, # Rails ʹΑͬͯར༻͞ΕΔ ! ! :as =>:company, # Rails ʹΑͬͯར༻͞ΕΔ ! ! :nofollow => true, # উखʹ௥Ճͨ͠ύϥϝʔλ ! ! :mobile_only => true # উखʹ௥Ճͨ͠ύϥϝʔλ ! } end .. ུ end end ͜͜Ͱఆٛͨ͠ύϥϝʔλ͸ Rails.application.routes.recognize_path Ͱऔಘ͢Δଞɺ֤ΞΫγϣϯͷ ύϥϝʔλʹϚʔδ͞Εͯίϯτϩʔϥͷ params ϝιου͔Βࢀর͢Δ͜ͱ΋Ͱ͖·͢ɻϧʔτఆٛʹ௥Ճͨ͠ύϥ ϝʔλ͕ར༻Ͱ͖Δ͜ͱ͕Θ͔ͬͨͷͰɺඞཁͦ͏ͳՕॴʹରԠ͢ΔॲཧΛຒΊ·͢ɻ ϨΠΞ΢τϑΝΠϧ ݱࡏͷURL͕ noindex ࢦఆ͞Ε͍ͯͨΒɺmeta λάΛग़ྗ͢ΔΑ͏ʹ͠·͢ɻ link_to / url_for ͜Ε͸ Rails ͷఏڙ͢Δ link_to ϔϧύʔΛॻ͖׵͑·͢ɻ image_tag , form_tag ͳͲͰ΋಺෦Ͱ url_for ͕ݺ͹Εͯ ͍ΔͷͰɺͪ͜ΒΛमਖ਼͢ΔࣄͰશମతʹಈ࡞ΛมߋͰ͖·͢ɻ ϦϯΫઌͱͯ͠ੜ੒ͨ͠ URL͕ఆٛͰ nofollow ࢦఆ͞Ε͍ͯͨΒ rel=nofollowΛϦϯΫʹ෇༩͢ΔΑ͏ʹमਖ਼ɻ ϦϯΫઌͱݱࡏͷϖʔδͷϓϩτίϧ͕ҟͳΕ͹ http:// ͔ΒϦϯΫ͢ΔΑ͏ʹमਖ਼ɻ ϕʔείϯτϩʔϥ SSLΛඞཁͱ͢Δϖʔδ͔Ͳ͏͔ͷ৘ใΛ URL ఆ͔ٛΒऔಘ͠ɺݱࡏͷϓϩτίϧͱ͖ͭ͋ΘͤͯϦμΠϨΫτͤ͞ ·͢ɻ ΫϥΠΞϯτ͕ ϞόΠϧͩͬͨ৔߹ʹ pc_only ͳΒτοϓ΁ϦμΠϨΫτ͠·͢ɻٯͷύλʔϯ΋ಉ༷Ͱ͢ɻ ભҠઌΛࢠίϯτϩʔϥͰΧελϚΠζՄೳͳΑ͏ʹɺભҠઌΛऔಘ͢Δॲཧ͸ίϯτϩʔϥͷΠϯελϯεϝιο υʹ͠·͢ɻ Ruby and Rails ิ଍ Ruby and Rails ิ଍
  23. ࣦഊஊ : APIαΠτͰAPIͷॲཧ݁ՌΛ௚઀Ϟσϧσʔλͱͯ͠ը໘ʹ౉͢΂͖Ͱ͸ͳ͍ ྫ͑͹APIͷ݁Ռ͕ json Ͱฦ͞ΕΔ৔߹ɺJSON.parse ͨ݁͠Ռ͕ Hash ʹͳΔͷͰɺͦͷ··ը໘ʹ౉ͨ͘͠ͳΔ ༠࿭ʹ͔ΒΕ·͢ɻAPI͕े෼ʹۀ຿୯ҐͱҰக͍ͯ͠Δ৔߹ɺͦͷ༠࿭͸ͱͯ΋ڧ͍ͱࢥ͍·͢ɻ࣮ࡍͦ͏ͯ͠͠·͍

    ·ͨ͠ɻ ͔͠͠ɺͦΕΒͷϝϦοτʹର߅͢Δʹิͬͯ͋·Γ͋ΔϝϦοτ͕ View༻ͷϞσϧΛ༻ҙ͢Δํࣜʹ͸͋Γ·͢ɻ ·ͨɺjson ௚઀Ϟσϧํࣜʹ͸ڊେͳσϝϦοτ͕͋Γ·͢ɻ ͦΕΛޠΔͷ͸·ͨ࣍ճɻ Ruby and Rails ิ଍ Ruby and Rails ิ଍