ii

Similar documents
2 Rails pico planner camel case camel pico planner _ pico_planner snake case snake - chain case chain pico planner pico-planner CSS id class 2.3 Rails

9 rbenv rbenv ruby 9.1 rbenv rbenv rbenv ruby ruby-build ruby 9.2 rbenv macos.bash_profile ~/.bash_profile ~/.bash_profile.bak $ touch ~/.bash_profile

IIJ Technical WEEK アプリ開発を楽にするRuby PaaS「MOGOK」について

Javaと.NET

™…

ii

利用者




パソコン機能ガイド

パソコン機能ガイド

8 4 end 5 6 private def message 7 'Hello' 8 end 9 end g = Greeting.new 12 g.hello $ ruby lib/lessons/greeting.rb Hello Ruby public method protec

2004年度日本経団連規制改革要望

困ったときのQ&A

I


01_SWGuide_V8.50.fm

はしがき・目次・事例目次・凡例.indd

II

活用ガイド (ハードウェア編)

橡6.プログラム.doc

vuejs_meetup.key

A : kerl kerl Erlang/OTP Erlang/OTP 2 2 Elixir/Phoenix URL 2 PDF A.2 Bash macos.bash_profile exp


Step2 入門


Microsoft Word - 51プログラム名簿目次070913w.doc


3 top#index 1 web router.ex web/router.ex 12 scope "/", NanoPlanner do 13 pipe_through browser get "/", TopController, index 16 end URL / to

エクセルカバー入稿用.indd

SC-85X2取説


<4D F736F F F696E74202D C835B B E B8CDD8AB B83685D>

01_.g.r..

vi アハ ート2 アハ ート3 アハ ート4 アハ ート5 アハ ート6 アハ ート7 アハ ート8 アハ ート9 アハ ート10 アハ ート11 アハ ート12 アハ ート13 アハ ート14 アハ ート15 アハ ート16 アハ ート17 アハ ート18 アハ ート19 アハ ート20 アハ

Chapter 1 イントロダクション p.21 第 2 段落 p.42 第 2 段落の 1 行目 p.45 Hint 美しいコードが書けるから Rails を選んだ美しいコードが書けるから Ruby を選んだフォルダ main app controllers を開いてみましょう フォルダ app

目次 1. Serverspec とは 1.1. Serverspecとは 1.2. Serverspecで出来る事 2. セットアップ 2.1. 必要なもの 2.2. インストール 3. デモ 3.1. デモ環境について 3.2. テスト対象サーバーの登録 3.3. サンプルテストの中身 3.4.

Ruby on Rails (RoR) を弄る

困ったときのQ&A

活用ガイド (ソフトウェア編)

学習内容と日常生活との関連性の研究-まえがき・概要・目次

ユーザーズガイド

III


これわかWord2010_第1部_ indd

パワポカバー入稿用.indd

これでわかるAccess2010

VB-C50i/VB-C50iR 使用説明書

i

untitled

i

2

活用ガイド (ソフトウェア編)

平成18年版 男女共同参画白書

レーザビームプリンタ Satera ユーザーズガイド

untitled

(28) SFC ( /Web

リファレンス

目次情報


基礎 Ruby on Rails 初版第 1 刷正誤表 基礎 Ruby on Rails ( 黒田努 佐藤和人著 株式会社オイアクス監修 インプレスジャパン刊 ) 初版第 1 刷 の正誤表です 特に重要な項目には 印を付しました また 付録 CD-ROM において chapter3 ディレクトリの中

GitLab + Dokku で作る CI/ CD 環境 Kazuhiro NISHIYAMA 第 78 回 Ruby 関西勉強会 2017/07/29 Powered by Rabbit 2.2.0

SPP24_Program_WOC(J)-15

結婚生活を強める

『保守の比較政治学』

C ontents VI VII

01_Rails_chap01.qx


bash on Ubuntu on Windows bash on Ubuntu on Windows bash on Ubuntu on Windows bash on Ubuntu on Windows bash on Ubuntu on Windows ˆ Windows10 64bit Wi

困ったときのQ&A

Agenda! 事前準備

初等協会5

困ったときのQ&A

GitLab6セットアップガイド.pdf



OFISTAR H7000ファクス編(2版 )

IIJ GIO, SaaS, MOGOK

MultiPASS B-20 MultiPASS Suite 3.10使用説明書

6 (1) app.html.eex 28 lib/nano_planner_web/templates/layout/app.html.eex 27 <footer> Oiax Inc <%= this_year() %> Oiax Inc. 29 </footer>

PHP4徹底攻略 改訂版

Emacs Ruby..


I

Rails4でつくるInstagramビューアーアプリ

活用ガイド (ソフトウェア編)

第 1 章ターミナルの使い方 Ubuntu の場合は同種のソフトウェアに 端末 という名前が付いていますが 本書では OS X に合わせて ターミナル と呼ぶことにします 端末を起動するには Dash *1 に対して term というキーワードを入力し 検索結果の中から 端末 を探してクリックします

ONLINE_MANUAL

ONLINE_MANUAL

Agenda 2

OB6-KEGGonRails-Kibukawa

『戦時経済体制の構想と展開』

1...1 I...1 II III IV V...5 VI I...6 II I II III... 54

リファレンス


RailsによるアジャイルWebアプリケーション開発 第4版


ESD-巻頭言[ ].indd

2

Transcription:

ii

iii

iv

v

vi

4 get "lesson/:action(/:name)" => "lesson" 5 6 resources :members 7 end Sato <%= link_to "Home", root_path, class: "menu" %> mac:rails taro$ cd asagao mac:asagao taro$ bin/rails s mac:asagao taro$ C: rails asagao> Windows / chapter3/app/controllers chapter3 app controllers \ vii

Mac \ o \ http://www.oiax.jp/rails4book chapter4/app/models/member.rb chapter4 app models member.rb chapter1 chapter7 chapter6a chapter6b chapter6a chapter6b section8-2 bundle install bin/rails s viii

mac:chapter1 taro$ bundle install mac:chapter1 taro$ bin/rails s bin/rails s bin/rake db:reset mac:chapter4 taro$ bundle install mac:chapter4 taro$ bin/rake db:reset mac:chapter4 taro$ bin/rails s bin/ ruby C: rails chapter4> bundle install C: rails chapter4> ruby bin/rake db:reset C: rails chapter4> ruby bin/rails s ix

...iii...v Chapter1... 2 1.1 Ruby on Rails...4 Ruby on Rails... 4 MVC... 8 Rails... 9... 11 1.2 Rails...14... 14 Mac... 15 Windows... 21... 25 Bundler... 27 1.3 Rails...31... 31... 33... 34... 37...41 Chapter2 Ruby... 42 2.1...44 Ruby... 44... 47... 54 2.2...59... 59... 66... 70... 74 2.3...77... 77... 78... 84... 88 x

2.4...92 Ruby... 92... 95... 98... 100... 103 Ruby... 107...111 Chapter3... 114 3.1 Rails HTTP...116 HTTP... 116 Rails... 120... 122 3.2...127... 127... 129... 132... 134 3.3...137... 137... 142... 145... 148 3.4...152... 152... 154... 156... 161...166 Chapter4... 168 4.1...170... 170 Rails... 171... 173... 175 Rake... 176 4.2...178... 178... 179 members... 181... 183 xi

4.3...188... 188... 191 4.4...195 find find_by... 195... 197...207 Chapter5... 210 5.1 REST...212... 212... 216 5.2 7...219 MembersController... 219... 220... 228...232 Chapter6... 234 6.1...236... 236... 237... 240... 244 6.2...250... 250... 251... 255 6.3...258... 258... 263 6.4...266 Rails... 266... 267 YAML... 273... 275...281 Chapter7... 284 7.1...286... 286... 287 xii

7.2...290... 290... 293 Factory Girl... 296 7.3...300 Article... 300... 302... 309 7.4...314... 314... 316 ArticlesController... 317 TopController... 329 7.5...331... 331...334 Chapter8... 336 8.1...338... 338 Sass... 342 CoffeeScript... 346 Turbolinks... 349 8.2...351... 351... 355... 359... 365... 371 8.3...376... 376... 380 8.4...383... 383 AccountsController... 384 8.5...389 Rails... 389... 391... 395 8.6...398 will_paginate... 398 will_paginate... 400...406 Chapter9... 408 9.1...410 xiii

... 410... 412 9.2 1...419... 419... 422 Entry... 425... 429... 435 9.3 1 1...439... 439 MemberImage... 441... 446... 450 9.4...457... 457... 461... 464 9.5...467... 467... 472... 477... 482...488 A... 490 B MySQL... 492 C Ruby... 496 D validates... 500 E... 504 F... 509...514... 74...109...194 REST... 218 scaffold...249...278...420 xiv

1

1 1.1 Ruby on Rails Ruby on Rails MVC Rails 1.2 Rails Mac Windows Bundler 1.3 Rails 2

1 3

1.1 Ruby on Rails Ruby on Rails Rails 4

1 1 Ruby on Rails Rails URL http://rubyonrails.org/ Rails Riding Rails Ruby on Rails http://weblog.rubyonrails.org/ 5

http://guides.rubyonrails.org/ http://railsguides.jp/ Ruby on Rails API http://api.rubyonrails.org/ Ruby on Rails Rails David Heinemeier Hansson DHH 37signals Basecamp Basecamp Rails http://david.heinemeierhansson.com/ http://itpro.nikkeibp.co.jp/article/news/20060620/241346/ Ruby Rails 6

1 1 Ruby Ruby Matz 1995 Ruby http://www.rubyist.net/~matz/ Ruby Rails 1.0 2005/12/13 3.0 2010/08/29 1.1 2006/03/28 3.1 2011/04/31 1.2 2007/01/19 3.2 2012/01/20 2.0 2007/12/07 4.0 2013/06/25 2.1 2008/06/01 4.1 2014/04/08 2.2 2008/11/21 4.2 2014/12/19 2.3 2009/03/16 5 2015? 7

MVC Rails MVC 8

1 1 members Member member.rb Rails Rails 9

rails & = /members /1 < %... % > rake birthday @member.birthday 10

1 1 @member.entries 11

12

1 1 chapter3 section9-5 13

1.2 Rails Mac/Windows Mac 14

1 1 Windows http://www.oiax.jp/rails4book Mac Mac Ruby Rails Mac Ruby RubyGems Mac Xcode 15

MacPorts Homebrew MacPorts Homebrew Mac Linux Homebrew Ruby rbenv MacPorts Homebrew MacPorts Homebrew MacPorts /opt/local Ruby Homebrew rbenv /Users/taro /.rbenv/ Ruby MacPorts Ruby gem sudo bundle Homebrew rbenv Ruby MacPorts Homebrew 16

1 1 mac:~ taro$ xcode-select --install MacPorts Ruby http://www.macports.org/ 17

mac:~ taro$ sudo port install ruby22 ruby22 ruby mac:~ taro$ sudo port select ruby ruby22 mac:~ taro$ ruby -v ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14] sudo port install ruby23 sudo port select ruby ruby23 Homebrew rbenv Ruby http://brew.sh/ 18

1 1 mac:~ taro$ ruby -e "$(curl -fssl https://raw.githubusercontent.com/homebrew/ install/master/install)" mac:~ taro$ brew install rbenv ruby-build.bash_profile eval "$(rbenv init -)" mac:~ taro$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile.bash_profile mac:~ taro$ source.bash_profile mac:~ taro$ rbenv install 2.2.1 rbenv versions mac:~ taro$ rbenv versions * system (set by /Users/taro/.rbenv/version) 2.2.1 19

mac:~ taro$ rbenv local 2.2.1 mac:~ taro$ ruby -v ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14] rbenv install 2.3.0 rbenv local 2.3.0 Rails gem --version "4.2.1" sudo mac:~ taro$ sudo gem install rails --version "4.2.1" --no-rdoc --no-ri sudo mac:~ taro$ gem install rails --version "4.2.1" --no-rdoc --no-ri --no-ri --no-rdoc rails mac:~ taro$ rails -v Rails 4.2.1 20

1 Rails SQLite3 SQLite3 Mac SQLite3 Windows SQLite3 Bundler Gem sqlite3 SQLite3 Ruby SQLite3 Rails SQLite3 MySQL B MySQL 1 Windows Ruby http://rubyinstaller.org/ 21

Windows Ruby 2015 3 Windows Ruby 2.2 Rails Ruby 2.2 Rails Windows C: Users taro> ruby -v ruby 2.1.5p273 (2014-11-13 revision 48405) [i386-mingw32] 22

1 DevKit 1 C: devkit Rails C: devkit devkitvars C: Users taro> C: devkit devkitvars gem bundle cacert.pem C: Users taro http://curl.haxx.se/docs/caextract.html cacert.pem cacert.pem.txt cacert.pem C: Users taro 23

C: Users taro> set SSL_CERT_FILE=C: Users taro cacert.pem gem C: Users taro> gem install rails --version "4.2.1" --no-rdoc --no-ri gem bin/rails s Windows Ruby C: Users taro> rails -v Rails 4.2.1 24

1 Mac Windows Rails Gem Ruby gems 2.2.0 gems Active Record activerecord- Mac MacPorts /opt/local/ lib/ruby2.2 Homebrew rbenv.rbenv/ versions/2.2.0/lib/ruby Windows C: Ruby21 lib ruby 1 /Users/taro rails mkdir cd mac:~ taro$ mkdir rails mac:~ taro$ cd rails C: Users rails C: Users > cd C: > mkdir rails C: > cd rails 25

Mac Mac pwd mac:~ taro$ pwd /Users/taro/rails/asagao 1.bash_profile taro@mac~/rails/asagao$ export PS1=" u@ h w$ ".bash_profile nano.bash_profile rails rails new --skip-bundle bundle install bundle mac:rails taro$ rails new asagao --skip-bundle create create README.rdoc create Rakefile create config.ru create vendor/assets/stylesheets create vendor/assets/stylesheets/.keep rails new asagao asagao bundle install 26

1 1 mac:rails taro$ cd asagao mac:asagao taro$ bundle install Fetching gem metadata from https://rubygems.org/... Resolving dependencies... Using rake 10.4.2 Using i18n 0.7.0 Using json 1.8.2 Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. Windows bundle Windows gem bundle DevKit SSL C: rails asagao> C: devkit devkitvars C: rails asagao> set SSL_CERT_FILE=C: Users taro cacert.pem rails new Rails rails new Rails Rails rails _ _ mac:rails taro$ rails _4.1.9_ new asagao --skip-bundle Bundler 27

bundle install rails new Gemfile Gemfile gem ' ' 1 source 'https://rubygems.org' 2 3 4 # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 5 gem 'rails', '4.2.1' 6 # Use sqlite3 as the database for Active Record 7 gem 'sqlite3' 8 # Use SCSS for stylesheets 9 gem 'sass-rails', '~> 5.0' 10 # Use Uglifier as compressor for JavaScript assets 11 gem 'uglifier', '>= 1.3.0' 12 # Use CoffeeScript for.coffee assets and views 13 gem 'coffee-rails', '~> 4.1.0' 28

1 Gemfile Gemfile Gem 1 gem 'rails', '4.2.1' # 4.2.1 gem 'sqlite3' # OK gem 'uglifier', '>= 1.3.0' # 1.3.0 gem 'coffee-rails', '~> 4.1.0' # 4.1.0 4.2 rails-i18n Chapter 6 factory_girl Chapter 7 bcrypt-ruby Chapter 8 will_paginate Chapter 8 Gemfile bundle install Gemfile Gemfile.lock Gemfile.lock Gemfile.lock 1 GEM 2 remote: https://rubygems.org/ 3 specs: 4 actionmailer (4.2.1) 5 actionpack (= 4.2.1) 6 actionview (= 4.2.1) 7 activejob (= 4.2.1) 8 mail (~> 2.5, >= 2.5.4) 9 rails-dom-testing (~> 1.0, >= 1.0.5) Gemfile.lock bundle install Gemfile.lock bundle install chapter1 chapter1 bundle install 29

bundle bundle install bundle list Gem bundle check Gem The Gemfile's dependencies are satisfied bundle update Gemfile.lock Gemfile Gem Gemfile.lock Gem 30

1 1.3 Rails 1 asagao bin/rails s bin/rails server mac:asagao taro$ bin/rails s => Booting WEBrick => Rails 4.2.1 application starting in development on http://localhost:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server [2015-02-11 16:45:13] INFO WEBrick 1.3.1 [2015-02-11 16:45:13] INFO ruby 2.2.1 (2015-02-26) [x86_64-darwin14] [2015-02-11 16:45:13] INFO WEBrick::HTTPServer#start: pid=4577 port=3000 ruby bin/rails s ruby bin/rails server ruby C: rails asagao> ruby bin/rails s http://localhost:3000/ http://127.0.0.1:3000/ 31

c C WEBrick WEBrick Ruby Ruby Rails WEBrick 1 Rails Rails Ruby on Rails MySQL SQLite3 MySQL bin/rails s bin/rake db:create Chapter 4 B Rails SQLite3 32

1 1 app config db app config app Chapter bin HINT config Chapter db Chapter 4 doc lib rake log public test Chapter 7 tmp vendor bin bin/ rails 1.2 Rails rails bin/rails bin 33

Rails asagao Rails 4.2.1 Rails bin/rails Rails config/initializers generators.rb 1 Rails.application.config.generators do g 2 g.helper false # 3 g.assets false # CSS, JavaScript 4 g.skip_routes true # config/routes.rb 5 g.test_framework false # 6 end bin/rails g bin/rails g rails g controller TopController index bin/ rails g bin/rails generate ruby mac:asagao taro$ bin/rails g controller top index create app/controllers/top_controller.rb route get 'top/index' invoke erb create app/views/top create app/views/top/index.html.erb 34

1 app/controllers top_controller.rb 1 class TopController < ApplicationController def index end end TopController TopController ApplicationController TopController index index Rails UTF-8 Mac Atom https://atom.io/ Windows Atom http://www5f.biglobe.ne.jp/~t-susumu/ http://hide.maruo.co.jp/ 35

UTF-8 LF UNIX Windows UNIX HINT config routes.rb Rails.application.routes.draw do end 1 Rails.application.routes.draw do 2 root "top#index" 3 end http://www.oiax.jp/ / TopController index bin/rails s http:// localhost:3000/ TopController index 36

1 Windows 2015 3 Windows TypeError: Gemfile 1 gem 'coffee-script-source', '1.8.0' Gem coffee-script-source C: rails asagao> bundle update coffee-script-source index app/ views/top index.html.erb.erb index.html.erb <h1> </h1> <p> Rails </p> http://localhost:3000/ 37

UTF-8 Rails UTF-8 Rails Ruby.rb.erb UTF-8 Windows TeraPad UTF-8 UTF-8N Unicode(UTF-8) BOM bin/rails g bin/rails g controller top TopController index index. html.erb Rails app/controllers top_controller.rb index @message @message " " 1 class TopController < ApplicationController 2 def index 3 @message = " " 4 end 5 end app/views/top index.html.erb <%= %> @message 1 <h1><%= @message %></h1> 2 <p> Rails </p> 38

1 http://localhost:3000/ @message 1 Rails WEBrick WEBrick bin/rails g 1 Rails Ruby on Rails 2015 5 Rails 5 Rails 4.2 39