facebook twitter hatena line email

Ruby/rails/helloworld

提供: 初心者エンジニアの簡易メモ
2017年11月4日 (土) 12:10時点におけるAdmin (トーク | 投稿記録)による版 (httpアクセス)

移動: 案内検索

プロジェクト作成

rails new helloworld

プロジェクト作成(mysqlを使う場合はこちら

rails new helloworld -d mysql 

コントローラー作成

rails generate controller test hello

testはコントローラー名、helloはアクション名、ルータが追記(configs/routes.rb)

     create  app/controllers/test_controller.rb
      route  get 'test/hello'
     invoke  erb
     create    app/views/test
     create    app/views/test/hello.html.erb
     invoke  test_unit
     create    test/controllers/test_controller_test.rb
     invoke  helper
     create    app/helpers/test_helper.rb
     invoke    test_unit
     invoke  assets
     invoke    coffee
     create      app/assets/javascripts/test.coffee
     invoke    scss
     create      app/assets/stylesheets/test.scss

アクション作成

app/controllers/test_controller.rb

class TestController < ApplicationController
  def hello
  end
end

ビュー作成

app/views/test/hello.html.erb

 <h1>Test#hello</h1>
 <p>Find me in app/views/test/hello.html.erb</p>

httpアクセス

ttp://localhost/test/hello

controllerを削除する場合

rails destroy controller test