「Tabetai」の版間の差分

提供: wikipokpok
移動先: 案内検索
(home)
(create application)
15行目: 15行目:
  
 
  % bundle install
 
  % bundle install
 +
 +
サーバー側
 +
<nowiki>$ bundle install  --without test development
 +
 +
database.yml username:などを確認する (2箇所)
 +
 +
/config/environments/production.rb</nowiki>
  
 
  % bin/setup
 
  % bin/setup

2023年7月5日 (水) 11:54時点における版

準備

プロジェクトディレクトリ作成 移動

バージョン確認

create application

% rails new . --css=tailwind --css=sass --javascript=esbuild --database=postgresql
% bin/bundle add tailwindcss-rails
% bin/rails tailwindcss:install
gem 'devise', '~> 4.9', '>= 4.9.2'
% bundle install

サーバー側

$ bundle install  --without test development

database.yml username:などを確認する (2箇所)

/config/environments/production.rb
% bin/setup

テスト用のデータで開発用のデータをつくる設定

# db/seeds.rb

puts "\n== Seeding the database with fixtures =="
system("bin/rails db:fixtures:load")

user

% bin/rails generate devise:install
アプリケーションの設定に応じて、いくつかの手動のセットアップが必要です:

1. 環境ファイルでデフォルトのURLオプションを定義してください。以下は、開発環境に適したdefault_url_optionsの例です。config/environments/development.rbに追加します:

   config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

   本番環境では、:hostをアプリケーションの実際のホストに設定する必要があります。

   * すべてのアプリケーションに必要です。 *

2. config/routes.rbでroot_urlを*何か*に定義してください。例:

   root to: "home#index"

   * API専用アプリケーションには必要ありません。 *

3. app/views/layouts/application.html.erbにフラッシュメッセージがあることを確認してください。例:

   <p class="notice"><%= notice %></p>
   <p class="alert"><%= alert %></p>

   * API専用アプリケーションには必要ありません。 *

4. カスタマイズするために、Deviseビューをアプリケーションにコピーするには、次のコマンドを実行します:

   rails g devise:views

   * 必須ではありません。 *

1

# config/environments/development.rb
  host = 'http://koresore.pokpok.jp'
  config.action_mailer.default_url_options = { host: host }

2

# app/views/layouts/application.html.erb
<p class="notice"><%= notice %></p>
 <p class="alert"><%= alert %></p>

Modelを作成

$ bin/rails generate devise User
$ bin/rails db:migrate

Viewを作成

$ rails generate devise:views users

ログインしないとアクセスできないようにする

# app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
  before_action :authenticate_user!, unless: :devise_controller?
end

home

ホームを作る

% rails generate controller Pages home

homeコントローラーはパブリックなので、認証をはずす

# app/controllers/pages_controller.rb

 skip_before_action :authenticate_user!

ルートパス

# config/routes.rb

root to: "pages#home"