AR삽질러

初めてのRuby on Rails Controller作成, トラブルシューティング (1) 본문

Ruby/RubyOnRails-日本語

初めてのRuby on Rails Controller作成, トラブルシューティング (1)

아랑팡팡 2023. 12. 27. 00:48
728x90

 

Rails Controller作成

 

例題

 - ブラウザの画面にHello Worldと表示するプログラム

 

最初の画面

 

1. Controller作成

rails generate controller users index
rails g controller users index

 

class UsersController < ApplicationController
  def index
    @hello = "Hello World!"
  end
end

 

Rails.application.routes.draw do
  get 'users/index'
  # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

  # Defines the root path route ("/")
  # root "articles#index"
end

 

<h1>Users#index</h1>
<p>Find me in app/views/users/index.html.erb</p>

<h1><%= @hello %><h1>

 

 


 

2.トラブルシューティングのアイディアを紹介

 - プロクラムが期待したとおり動かない場合は、勉強になりますので、ご自身で解決にチャレンジしてみましょう。

 

<h1>Users#index</h1>
<p>Find me in app/views/users/index.html.erb</p>

<h1><%= hello %><h1>

 

 

 

728x90
반응형
LIST