2011年7月13日水曜日

WindowsでRuby on Railsをインスト

■■■■Rails 3.0.9バージョンのインスト■■■■
>gem update --system
>gem install rails sqlite3

■■■■SQLITEのドライバインスト■■■■■
 http://www.sqlite.org/sqlitedll-3_7_3.zip
よりsqliteのドライバをインストしパスの通っている・Rubyのbin等にコピーしてください


■■■■Rails3のアプリの作成■■■■■

>rails new demo

create
create  README
create  Rakefile
create  config.ru
create  .gitignore
create  Gemfile
create  app
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  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/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  log
create  log/server.log
create  log/production.log
create  log/development.log
create  log/test.log
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  public/images
create  public/images/rails.png
create  public/stylesheets
create  public/stylesheets/.gitkeep
create  public/javascripts
create  public/javascripts/application.js
create  public/javascripts/controls.js
create  public/javascripts/dragdrop.js
create  public/javascripts/effects.js
create  public/javascripts/prototype.js
create  public/javascripts/rails.js
create  script
create  script/rails
create  test
create  test/fixtures
create  test/functional
create  test/integration
create  test/performance/browsing_test.rb
create  test/test_helper.rb
create  test/unit
create  tmp
create  tmp/sessions
create  tmp/sockets
create  tmp/cache
create  tmp/pids
create  vendor/plugins
create  vendor/plugins/.gitkeep

が作成されます。


■■■■Railsのwebサーバの起動■■■■■
>rails server
で起動、このときセキュリティの警告がでますが解除してください。

次に「http://localhost:3000/」にアクセスしてみてください、
WEBrickサーバが立ち上がり「welcome aboard」と表示されるはずです。


■■■■say/indexを表示■■■■■
>rails generate controller say index
上記のコマンドは「say」がコントローラ名で、
「index」がアクションになります。


下記がはきだされるはずです。
create  app/controllers/say_controller.rb
 route  get "say/index"
invoke  erb
create    app/views/say
create    app/views/say/index.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


それでは「http://localhost:3000/say/index」にアクセスしてみましょう。
「Say#index
Find me in app/views/say/index.html.erb」と表示されているはずです。

コントローラの中身は
class SayController < ApplicationController
  def index
  end
end
となっているはずです。http://localhost:3000/say/indexのindexがメソッドになります。

■■■■say/helloを作成しを表示■■■■■
class SayController < ApplicationController
  def index
  end
  def hello
  end
end
を追加、demo/config/routes.brに
get "say/hello"を追加し、
また、demo\app\viwe\say\hello.html.erbを作成し、<h1>hello</h1>
「http://localhost:3000/say/hello」を表示するとhelloと表示されるはずです。