Ruby On Rails開発環境For Windows(更新)


一、Windows下のLIls環境のインストール
簡単です。
1.Rails DevKitをダウンロードする:Ralsinstaller-version.exeダウンロードアドレスhttp://railsinstaller.org/ 
   LIlsinstaller-2.11.exeダウンロードアドレスhttp://download.csdn.net/download/loveanna7/5147502
2.LIlsを設置する:LIlsinstaller-version.exeのインストールを行う。ばかのインストール(少し注意してください。インストールのパスにスペースがないようにしてください。)他のコンポーネントも一緒に取り付けます。ルビー、gem、bundleなどが含まれています。
3.インストールが完了した時点で、その画面のチェックボックスを選択すると、私たちはgit設定に入ります。自動的に端末を開けます。名前とメールボックスを入力すれば自動的に配置されます。
4.配置が完了すると、端末は自動的にC:\Sitesに入ります。私達は今私達がインストールした環境のバージョン番号を確認できます。LIls-v;gem-v;bundle-v
実行ログ:
# Rails Environment Configuration.

Your git configuration is incomplete.
user.name and user.email are required for properly using git and services such
as GitHub ( http://github.com/ ).

 Please enter your name, for example mine is: Wayne E. Seguin
name > Jarry Li
Setting user.name to Jarry Li

 Please enter your email address, for example mine is: [email protected]
email > [email protected]
Setting user.email to [email protected]
'clip'          ,         
      。

---
git:
  user.name:  Jarry Li
  user.email: [email protected]
  version:    git version 1.7.9.msysgit.0

ruby:
  bin:        D:/dev/RailsInstaller/Ruby1.9.2/bin/ruby.exe
  version:    ruby 1.9.3p125 (2012-02-16) [i386-mingw32]

rails:
  bin:        D:/dev/RailsInstaller/Ruby1.9.2/bin/rails.bat
  version:    Rails 3.2.1

ssh:
  public_key_location: C:\Documents and Settings\Administrator/.ssh/id_rsa.pub
  public_key_contents: ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxGnWu+Vl8ZuVbEg21/w2s
4UIOFPK9ujkl2r19Ysq2E94ZSvaPfjJj7PkN0619Ci35BtmAu14ChdFBWPLi8PhrZu5o0PSZao0wecXX
v8kcl27iaAIQtnXr9uz3319fZRDgx12V/DBnXD5NFI1BTQJVaPxM6SwblJJCDs/ELgR9Wg0x23t4e33s
z0AXkav4kFKbxlJFDXl8vAbauyLozkd28+jFUni8sFau4eDVkv4XVmFBLPAQPb5rSZ8Pmt8ci6Zj2JEX
9rCFr7qPPMiWgSlb2vC3d8S2Lwk+Ju1P/AqiAubemyZnRq25ar0W7Nx+sKjJpHzskthhwZ93UJkaRpxF
Q== Jarry Li 


NOTES:

  Your public ssh key (id_rsa.pub) has been automatically generated and copied t
o your clipboard.

C:\Sites>ruby -v
ruby 1.9.3p125 (2012-02-16) [i386-mingw32]

C:\Sites>rails -v
Rails 3.2.1

C:\Sites>gem -v
1.8.16

C:\Sites>bundle -v
Bundler version 1.0.22
 
二、新規アプリケーション
1.demoアプリケーションを作成します。例えば、E:\works\ruby、Lals new demoを実行して、demoというアプリケーションを作成します。
2.cdからdemoディレクトリへ
3.既定のLIlsサーバを起動する:LIls server
4.ブラウザが開くhttp://localhost:3000
Ruby On Rails开发环境For Windows(更新)_第1张图片
 
実行ログ:
C:\Sites>cd e:\works\

C:\Sites>e:

E:\works>mkdir ruby

E:\works>cd ruby

E:\works\ruby>rails new demo
      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 source index for https://rubygems.org/
Installing rake (10.0.3)
Installing i18n (0.6.4)
Installing multi_json (1.6.1)
Using activesupport (3.2.1)
Installing builder (3.0.4)
Using activemodel (3.2.1)
Using erubis (2.7.0)
Installing journey (1.0.4)
Installing rack (1.4.5)
Installing rack-cache (1.2)
Installing rack-test (0.6.2)
Using hike (1.2.1)
Installing tilt (1.3.5)
Installing sprockets (2.1.3)
Using actionpack (3.2.1)
Installing mime-types (1.21)
Using polyglot (0.3.3)
Installing treetop (1.4.12)
Installing mail (2.4.4)
Using actionmailer (3.2.1)
Using arel (3.0.2)
Installing tzinfo (0.3.37)
Using activerecord (3.2.1)
Using activeresource (3.2.1)
Using bundler (1.0.22)
Installing coffee-script-source (1.6.1)
Installing execjs (1.4.0)
Using coffee-script (2.2.0)
Installing rack-ssl (1.3.3)
Installing json (1.7.7) with native extensions
Installing rdoc (3.12.2)
Using thor (0.14.6)
Using railties (3.2.1)
Using coffee-rails (3.2.2)
Installing jquery-rails (2.2.1)
Using rails (3.2.1)
Installing sass (3.2.7)
Installing sass-rails (3.2.6)
Installing sqlite3 (1.3.7)
Installing uglifier (1.3.0)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem
is installed.

E:\works\ruby>cd demo

E:\works\ruby\demo>rails server
=> Booting WEBrick
=> Rails 3.2.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
        SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
        This poses a security threat. It is strongly recommended that you
        provide a secret to prevent exploits that may be possible from crafted
        cookies. This will not be supported in future versions of Rack, and
        future versions will even invalidate your existing user cookies.

        Called from: D:/dev/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/ac
tionpack-3.2.1/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `i
nitialize'.

[2013-03-14 10:01:15] INFO  WEBrick 1.3.1
[2013-03-14 10:01:15] INFO  ruby 1.9.3 (2012-02-16) [i386-mingw32]
[2013-03-14 10:01:15] INFO  WEBrick::HTTPServer#start: pid=4728 port=3000
 
三、ハローRails 
ハローワールドのプログラムを書いてみてください。端末を新しく開けて、Eにcdを送ります。\works\ruby\demo
1.Lalsでsayというコントローラを生成し、命令で:lals generate controller Say hello goodbye
ログ情報:
E:\works\ruby\demo>rails generate controller Say hello goodbye
        SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
        This poses a security threat. It is strongly recommended that you
        provide a secret to prevent exploits that may be possible from crafted
        cookies. This will not be supported in future versions of Rack, and
        future versions will even invalidate your existing user cookies.

        Called from: D:/dev/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/ac
tionpack-3.2.1/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `i
nitialize'.

      create  app/controllers/say_controller.rb
       route  get "say/goodbye"
       route  get "say/hello"
      invoke  erb
      create    app/views/say
      create    app/views/say/hello.html.erb
      create    app/views/say/goodbye.html.erb
      invoke  test_unit
      create    test/functional/say_controller_test.rb
      invoke  helper
      create    app/helpers/say_helper.rb
      invoke    test_unit
      create      test/unit/helpers/say_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/say.js.coffee
      invoke    scss
      create      app/assets/stylesheets/say.css.scss
 
 
2.コントローラdemo/ap/controllers/say_controller.rbコード
class SayController < ApplicationController
  def hello
  end

  def goodbye
  end
end
 
Application Controller類を継承していると見られますが、中には二つの空きがあります。
3.LIlsのurl要請、ブラウザアクセス:http://localhost:3000/say/hello
Ruby On Rails开发环境For Windows(更新)_第2张图片
私たちはLIls generateを実行している時に、6つのファイル1つのディレクトリsayを生成しました。このディレクトリはコントローラビューのテンプレートファイルを保存するために使われています。sayコントローラを作成しました。ビューはap/view/sayの中にあります。
デフォルトのLIlsは現在の動力と同名のファイルのテンプレートを探します。ここでは、app/views/say/hello.html.erbテンプレートファイルを修正します。ここにHTMLコードを追加すればいいです。
現在のコード

Say#hello

Find me in app/views/say/hello.html.erb

 
修正後:

Hello from Rails

 
ブラウザを更新します。
Ruby On Rails开发环境For Windows(更新)_第3张图片
4.テンプレートに動的な内容を追加します。ページを表示するたびに現在の時刻も表示されます。
テンプレートファイル用.httml.erb拡張は、ERbシステムを介してファイルの内容を拡張する必要があります。jsp/asp/phpのようなダイナミックページファイルです。ERbはライズのデフォルトインストールに含まれるフィルタです。
app/views/say/hello.html.erbテンプレートを変更し、現在の時間を表示するために追加します。

Hello from Rails

It is new

 
ブラウザを更新:
Ruby On Rails开发环境For Windows(更新)_第4张图片
5.「時間の取得」の方法をコントローラに書いても、表示は情報の表示のみを行います。
コントローラのハローメソッドを変更して、時間値を@timeのインスタンス変数にセットします。httml.erbテンプレートからインスタンス変数を出力すればいいです。
コントローラのアプリ/controllers/say_を修正します。controller.rb:
class SayController < ApplicationController
  def hello
  	@time = Time.now
  end

  def goodbye
  end
end
 
app/views/say/hello.html.erbテンプレートを修正します。

Hello from Rails

It is new

 
ブラウザを更新して、時間の更新だけを見ます。
 
四、ページを繋げる
1.アプリケーションを作成する時に、goodbyeの動作も作成します。対応するテンプレートアプリ/views/say/goodbye.html.erbは、今使っています。

Goodbye!

It was nice having you here.

 
2.開くhttp://localhost:3000/say/goodbye
Ruby On Rails开发环境For Windows(更新)_第5张图片
3.ハローとgoodbyeページを接続する:現在は2つのテンプレートページにリンクを追加し、互いにジャンプさせる必要があります。
hello.html.erb追加:

Say ハロー!

 
goodbye.html.erb追加:

Say Goodbye!

 
Ruby On Rails开发环境For Windows(更新)_第6张图片
Ruby On Rails开发环境For Windows(更新)_第7张图片
4.現在はこのように管理されていますが、アプリケーションをWebサーバの別のディレクトリに移行すると、これらのUrlは無効になります。実際にはRailsが提供するビューテンプレートにおける補助法を使用することができる。現在はサポート方法を使ってジャンプリンクを追加します。
修正hello.html.erb:

Hello from Rails

It is new

Time to say !

 
goodbye.html.erbを修正:

Goodbye!

It was nice having you here.

Say again.

 
link_ト()は、(LIlsでは、このような方法を補助方法(helper)と呼ぶ方法です。これは、ビューテンプレートを作成するのに便利です。)ここでは、括弧を省略します。
say_goodbye_pathパラメータは、LIlsが予測した値です。
Ruby On Rails开发环境For Windows(更新)_第8张图片
Ruby On Rails开发环境For Windows(更新)_第9张图片