facebook twitter hatena line email

「Ruby/rails/helloworld」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==プロジェクト作成== rails new helloworld ===プロジェクト作成(mysqlを使う場合はこちら=== rails new helloworld -d mysql ==コントロー...」)
 
(httpアクセス)
 
(同じ利用者による、間の5版が非表示)
行6: 行6:
  
 
==コントローラー作成==
 
==コントローラー作成==
  ruby script/rails generate controller test hello
+
  rails generate controller test hello
 
testはコントローラー名、helloはアクション名、ルータが追記(configs/routes.rb)
 
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
  
 
==アクション作成==
 
==アクション作成==
行17: 行33:
  
 
==ビュー作成==
 
==ビュー作成==
app/view/hello.html.erb
+
app/views/test/hello.html.erb
  <<nowiki />html><<nowiki />bodyhello</body></html>
+
<pre>
 +
  <h1>Test#hello</h1>
 +
<p>Find me in app/views/test/hello.html.erb</p>
 +
</pre>
 +
 
 +
==httpアクセス==
 +
ttp://localhost/test/hello
 +
 
 +
やり方は、以下を確認する
 +
 
 +
[[ruby/rails/サーバWEBrick]] [ショートカット]
 +
 
 +
[[ruby/rails/unicorn]] [ショートカット]
 +
 
 +
==controllerを削除する場合==
 +
rails destroy controller test

2022年9月21日 (水) 18:42時点における最新版

プロジェクト作成

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

やり方は、以下を確認する

ruby/rails/サーバWEBrick [ショートカット]

ruby/rails/unicorn [ショートカット]

controllerを削除する場合

rails destroy controller test