단계 1. Ruby 1.9.3 p-327 설치하기

http://www.ruby-lang.org/en/downloads/ 의 좌측 메뉴에서  Ruby 1.9.3-p327 를 클릭하여 다운로드하여 Ruby 1.9.3 설치한다.

 

단계 2. RubyGems 1.8.24  설치하기

http://rubygems.org/pages/download 에서 ZIP 을 클릭하여 rubygens-1,8.24.zip 을 다운로드하여 압축을 풀고, 명령 프롬프트에서 명령

프롬프트> set PATH=C:\ruby193\bin;%PATH%

으로 환경변수 PATH 를 설정하고, 명령

프롬프트> cd  {RubyGems가 설치된 폴더}\rubygems-1.8.24

으로 압축 해제된 폴더 안으로 들어가서 명령

프롬프트> ruby setup.rb

으로 RubyGems 1.8.24를 설치한다.

 

단계 3. Rails 3.2.9 설치하기

명령

프롬프트> gem install rails

으로 Rails 3,2,9를 설치한다.

 

단계 4. Rails 애플리케이션 생성하기

프롬프트> rails new myapp

하면 gem istall json -v '1.7.5' 를 확인하라는 에러 메세지가 뜬다. 명렬

프롬프트> gem install json -v=1.7.5

으로 json을 설치하려고 시도하지만 json 은 잘 설치되지 않는다. 이를 해결하자면  Devlopment-Kit 를 설치해야 한다.  http://rubyinstaller.org/downloads 의 좌측메뉴에서 DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe 를 클릭하여 다운로드하여 이를 실행한다.

* Devlopment-Kit의 사용 설명: https://github.com/oneclick/rubyinstaller/wiki/Development-Kit 을 참고한다.

Devlopment-Kit 가 설치된 폴더로 가서 명령 'ruby dk.rb install --force' 를 실행한다.

프롬프트> cd c:\DevKit

프롬프트> ruby dk.rb install --force 

Error loading 'config.yml'.  Have you run 'ruby dk.rb init' yet?

이런 에러를 내면서 위의 명령이  먹히지 않는 경우가 있다.

config.yml 파일이 없다고 불평을 하는 것 같은데, config,yml 파일을 만들기 위해 명령

프롬프트> ruby dk.rb init

을 실행해 보지만 더 길다란 에러메세지가 출력된다.

 c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:173:in `tr': invalid byte sequence i
n UTF-8 (ArgumentError)
        from c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:173:in `initialize'
        from c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:231:in `exception'
        from c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:231:in `raise'
        from c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:231:in `check'
        from c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:254:in `OpenKey'
        from c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:385:in `open'
        from c:/ruby193/lib/ruby/1.9.1/win32/registry.rb:496:in `open'
        from dk.rb:118:in `block in scan_for'
        from dk.rb:116:in `each'
        from dk.rb:116:in `scan_for'
        from dk.rb:138:in `block in installed_rubies'
        from dk.rb:138:in `collect'
        from dk.rb:138:in `installed_rubies'
        from dk.rb:146:in `init'
        from dk.rb:313:in `run'
        from dk.rb:332:in `<main>'

좀 황당하하기는 하지만, 잠시 https://groups.google.com/forum/#!msg/rubyinstaller/zCj6ttx_GdI/LPFdToNc4O0J 를 참고하면서 마음을 가다듬는다. 저 참고대로 따라서 할 것은 아니다. 이는 Ruby 1.9.3 버전에서 가끔 있을 수 있는 에러이다. 원인은 현재 명령 프롬프트의 코드페이지가 맞지 않아서 그런 것이다. 코드페이지가 utf-8로 되어 있었기 때문이다. DevKit 를 서치하는 동안만 잠시 MS939 로 돌아갔다 오면 된다. 

프롬프트> cp 949

프롬프트> ruby rk.db init

[INFO] found RubyInstaller v1.8.7 at C:/Ruby187
[INFO] found RubyInstaller v1.9.1 at C:/Ruby191
[INFO] found RubyInstaller v1.9.3 at C:/Ruby193

Initialization complete! Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.

프롬프트> ruby rk.rb install --force

[INFO] Installing 'C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/defaults/operating
_system.rb'
[INFO] Installing 'C:/Ruby187/lib/ruby/site_ruby/devkit.rb'
[INFO] Installing 'C:/Ruby191/lib/ruby/site_ruby/1.9.1/rubygems/defaults/operati
ng_system.rb'
[INFO] Installing 'C:/Ruby191/lib/ruby/site_ruby/devkit.rb'
[INFO] Updating convenience notice gem override for 'C:/Ruby193'
[INFO] Installing 'C:/Ruby193/lib/ruby/site_ruby/devkit.rb'

프롬프트> cp 65001

그 다음 명령

프롬프트> gem install json -v=1.7.5

을 실행한다. 그러면 json 이 잘 설치된다.

Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed json-1.7.5
1 gem installed
Installing ri documentation for json-1.7.5...
Installing RDoc documentation for json-1.7.5...

(아직 sqlite3가 설치되어 있지 않다면, 명령

프롬프트> gem install sqlite3

으로 sqlite3 를 설치한다.) 이제 명령

프롬프트> rails new myapp

으로  Rails 애플리케이션 myapp가 생성된다.

      create
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/assets/images/rails.png
      create  app/assets/javascripts/application.js
      create  app/assets/stylesheets/application.css
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/mailers
      create  app/models
      create  app/views/layouts/application.html.erb
      create  app/mailers/.gitkeep
      create  app/models/.gitkeep
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/secret_token.rb
      create  config/initializers/session_store.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  doc
      create  doc/README_FOR_APP
      create  lib
      create  lib/tasks
      create  lib/tasks/.gitkeep
      create  lib/assets
      create  lib/assets/.gitkeep
      create  log
      create  log/.gitkeep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/index.html
      create  public/robots.txt
      create  script
      create  script/rails
      create  test/fixtures
      create  test/fixtures/.gitkeep
      create  test/functional
      create  test/functional/.gitkeep
      create  test/integration
      create  test/integration/.gitkeep
      create  test/unit
      create  test/unit/.gitkeep
      create  test/performance/browsing_test.rb
      create  test/test_helper.rb
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/javascripts
      create  vendor/assets/javascripts/.gitkeep
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.gitkeep
      create  vendor/plugins
      create  vendor/plugins/.gitkeep
         run  bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..
Using rake (10.0.2)
Using i18n (0.6.1)
Using multi_json (1.3.7)
Using activesupport (3.2.9)
Using builder (3.0.4)
Using activemodel (3.2.9)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.1)
Using rack-cache (1.2)
Using rack-test (0.6.2)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.2.1)
Using actionpack (3.2.9)
Using mime-types (1.19)
Using polyglot (0.3.3)
Using treetop (1.4.12)
Using mail (2.4.4)
Using actionmailer (3.2.9)
Using arel (3.0.2)
Using tzinfo (0.3.35)
Using activerecord (3.2.9)
Using activeresource (3.2.9)
Using bundler (1.2.2)
Using coffee-script-source (1.4.0)
Using execjs (1.4.0)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.2)
Using json (1.7.5)
Installing rdoc (3.12)
Using thor (0.16.0)
Using railties (3.2.9)
Installing coffee-rails (3.2.2)
Installing jquery-rails (2.1.3)
Using rails (3.2.9)
Installing sass (3.2.3)
Installing sass-rails (3.2.5)
Using sqlite3 (1.3.6)
Installing uglifier (1.3.0)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem
is installed.
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
 = 1.8.7 : gem install rdoc-data; rdoc-data --install
 = 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!

 

단계 5. Rails 애플리케이션 실행하기

명령프롬프트> cd myapp

명령프롬프트> rails server

=> Rails 3.2.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-11-23 15:11:46] INFO  WEBrick 1.3.1
[2012-11-23 15:11:46] INFO  ruby 1.9.3 (2012-11-10) [i386-mingw32]
[2012-11-23 15:11:47] INFO  WEBrick::HTTPServer#start: pid=7468 port=3000

 

이제 웹브라우저로 http://localhost:3000 를 방문하면, 아래와 같은 Rails 애플리케이션의 초기화면이 뜬다.

 

 

 

단계 6: Home 컨트롤러 생성하기

프롬프트> rails generate controller home index

위 명령으로 notepad app/views/home/index.html.erb 이라는 파일이 자동으로 생성되어 있을 것이다. 이 파일의 내용은 딱 두 줄

         <h1>Home#index</h1>
         <p>Find me in app/views/home/index.html.erb</p>

이다. 이것이 웹브라우저에서 실행되게 하려면 public/index.html 파일을 삭제하거나 다른 이름으로 변경하고, config/routes.rb 파일의 내용을 다음과 같이 수정한다. (진하게 된 부분을 추가한다.)

Myapp::Application.routes.draw do
  get "home/index"

.............................................

  # You can have the root of your site routed with "root"
  # just remember to delete public/index.html.
  root :to => "home#index" 
  .............................................

 

 

이제 다시 서버를 다시 시작하고 웹브라우저로 http://localhost:3000 을 방문한다

프롬프트> rails server

 

 

Posted by Scripter
,