LoginSignup
0
1

More than 3 years have passed since last update.

Rails 作成 初期(個人アプリ用、雛形)

Last updated at Posted at 2019-11-02

個人のアプリを作成するとして

1 作りたいアプリのRailsの作成

$ rails _5.0.7.2_ new hidden378 -d mysql
$ cd hidden378

(hidden378には自分の作品名を入れましょう)

2 ルート、コントローラーの設定

$ bundle exec rake db:create # アプリのDB作成
$ rails g controller messages index # コントローラーの作成 ついでにアクションとビューも

3 コントローラーファイルができるのでインデックスのメソッド追記

messages.controller.rb
 class messagesController < ApplicationController
   def index
   end
 end

4 ビューにmessagesファイルができているのでindex.html.hamlのファイルを新しく作成しそこに確認用に適当な文字列を入れる

(例)Hello world!

   等

5 ルーティングの設定を行う、root_pathにアクセスした時messages#indexを呼び出す

(rails g controllerではrootの設定をしてくれないので自分で作らないといけない)

Rails,routes.rb
Rails.application.routes.draw do
   root to: 'messages#index'
end

6 http://localhost:3000 で確認してみましょう、4で設定した文字列が出てくると思います

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1