2
2

More than 3 years have passed since last update.

high_voltageでコントローラー不要のページを作成

Last updated at Posted at 2020-06-13

目的

プライバシーポリシーや利用規約などそれ1枚だけで完結する静的なページを作成したかった。
それだけにコントローラー作るのも……と思っていたら目的に合致したgemを発見。
自分でルーティング設定をする必要もありません。

詳細は公式を見れば分かります。内容も短くて分かりやすいです。
https://github.com/thoughtbot/high_voltage

higt_voltage導入

Gemfile
gem high_voltage
$ bundle install

ビューを設置。
これで完成。

app/views/pages/privacy_policy.html.erb
<h1>プライバシーポリシー</h1>

静的ページのデフォルトのURLは/pages/○○であるが、pagesを付けたくないときは以下のようにファイルを新規作成して設定すればよい。これで/○○のURLになる。

config/initializers/high_voltage.rb
HighVoltage.configure do |config|
  config.route_drawer = HighVoltage::RouteDrawers::Root
end

まとめ

ページ名 URL(デフォルト) URL(カスタム後) path
about /pages/about /about page_path("about")
2
2
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
2
2