Ruby/rails/helloworld
提供: 初心者エンジニアの簡易メモ
目次
プロジェクト作成
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
