LoginSignup
1
1

More than 5 years have passed since last update.

Ruby on Rails Tutorial で使用されていない技術

Last updated at Posted at 2019-02-23

View表示の高速化

slim

Gemfileへの記載追加

gem 'slim-rails'
gem 'html2slim'

使用できる状態にする

$ bundle update

変換

$ bundle exec erb2slim app/view/<適応するディレクトリ> (--delete)

Test用のライブラリ

RSpec

Gemfileに追加

group :development, :test do
  (省略)
  # RSpec
  gem 'rspec-rails'
end

bundleに適用

$ bundle update

rspecのインストール&ディレクトリ作成

$ rails g rspec:install

Capybara

準備

specに適用できるように準備する。
Headless Chromeを使用する。

spec/spec_helper.rb
require 'capybara/rspec'

RSpec.configure do |config|
  config.before(:each, type: system) do
    driven_by :selenium_chrome_headless
  end

  (省略)
end

Factory Bot

インストール

group :development, :test do
  (省略)
  # test fixture
  gem 'factory_bot_rails'
end

modelファイルにschemaを書き出す

gem 'annotate'
$ bundle exec annotate --exclude tests,fixtures,factories

上記でModelのみ対象となる。

ログイン機能

devise

注:最初に作成するべき。すでにUserモデルがあるとコンフリクトする。

公式Document:
https://github.com/plataformatec/devise/wiki

手順

Gemfileにかく。

# ユーザー登録
gem 'devise', '4.3.0'

アップデートする。

$ bundle update

インストールする

$ rails g devise:install

Userモデルに適応する。

$ rails g devise User

ファイルが色々できる。
migrationファイルもできているので、DBをアップデート。

$ rails db:migrate

さらにカスタマイズ

Viewをカスタマイズ

$ rails g devise:views users

Controllerをカスタマイズ

$ rails g devise:controllers users
$ rails g devise:controllers users

タグ機能

acts_as_taggable_on_engineを使用する。

検索

ransack

1
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
1
1