[Rails] How to simply put a link to a static page such as terms of use or privacy policy

If you are doing personal development, you will create terms of use and privacy policy. At that time, it is troublesome to prepare a controller for that purpose and write the routing. In that case, use the gem `` `high_voltage```!

Implementation procedure

1. Install Gem

Add'high_voltage' to Gemfile

$ docker-compose run app bundle install

I'm using Docker to build the environment. Depending on how you write Dockerfile and docker-compose.yml, if you rewrite Gemfile, you need to start over from build. I will omit this area this time.

2. Make a view

app/views/pagesIf the directory does not exist, create it.

$ mkdir -p app/views/pages

Create the file of the page you want to link, this time we will create the terms of use with haml. Replace the template engine from time to time.

$ touch app/views/pages/terms.html.haml

Write content.

haml:tearms.html.haml



 .term-wrapper
    %h1.uk-text-center Terms of Service
    %p These Terms of Use (hereinafter referred to as "Terms of Use") are professional! (Hereinafter referred to as "the secretariat") defines the terms of use of the service provided on this website (hereinafter referred to as "this service"). Registered users (hereinafter referred to as "users") are required to use this service in accordance with this agreement.
    %h2 Article 1 (applicable)
    %ol
      %li This agreement shall apply to all relationships related to the use of this service between the user and this secretariat.
      %li The secretariat may make various provisions (hereinafter referred to as "individual provisions") regarding this service, such as rules for use in addition to this agreement. These individual provisions shall form part of this agreement regardless of their name.
      %li If the provisions of this agreement contradict the provisions of the individual provisions of the preceding article, the provisions of the individual provisions shall prevail unless otherwise specified in the individual provisions.
    %h2 Article 2 (Registration)
    %ol

......(abridgement)

3. Paste the link (completed)

When you put a link, you can write the path as page_about ('terms').

haml:home.html.haml



= link_to 'Terms of service', page_path('terms')

Looking at the routing,

Prefix Verb URI Pattern    Controller#Action
  page GET  /pages/*id     high_voltage/pages#show

You can see that it is.

This completes the Terms of Service page for the time being! !!

Change the hierarchy

The default is https://hogehoge.com/pages/terms, so if you want to change this to hogehoge.com/terms, create config / initializers / high_voltage.rb and do the following: It is described as follows.

high_voltage.rb



HighVoltage.configure do |config|
  config.route_drawer = HighVoltage::RouteDrawers::Root
end

Looking at the routing,

Prefix Verb URI Pattern    Controller#Action
  page GET  /*id           high_voltage/pages#show

You can see that the pages are gone.

Thank you for reading to the end!

We output what we have learned every day! !! If you have any suggestions, I would appreciate it if you could comment! !!

Recommended Posts

[Rails] How to simply put a link to a static page such as terms of use or privacy policy
How to use JQuery in js.erb of Rails6
How to create a header or footer once and use it on another page
How to use ArgumentMatchers such as Mockito's any () in Kotlin
[Rails] How to use enum
How to use rails join
[Rails] How to use validation
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
[Rails] How to use Scope
[Rails] How to put a crown mark on the ranking function
[Ruby on Rails] "|| =" ← Summary of how to use this assignment operator
How to output a list of strings in JSF as comma-separated strings
[chown] How to change the owner of a file or directory
[Rails] How to use gem "devise"
[Rails] How to use devise (Note)
[Rails] How to use flash messages
How to use Ruby on Rails
How to use setDefaultCloseOperation () of JFrame
[Rails] How to use Active Storage
[Introduction to Rails] How to use render
[Java] How to use substring to cut out a part of a character string
[Rails] How to pass validation such as password when executing update action
[For Rails beginners] Summary of how to use RSpec (get an overview)