6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails4でtrailing_slashを付与する

Posted at

前提

  • Ruby 2.1.5
  • RubyOnRails 4.2.0

trailing_slashって??

URLの一番最後(末尾)にあるスラッシュ「/」のこと
(こんな説明は不要かと思いますが、念のため。。。)

trailing_slashを付与する方法

:one: 全てのURLに対して付与したい場合

application.rb
class Application < Rails::Application
 
    # Add trailing slash
    config.action_controller.default_url_options = { :trailing_slash => true }
 
end

:two: 一部のURLに対して付与したい場合

routes.rb

  get 'hoge/:id' => 'hoge#show', trailing_slash: true

参考資料

6
8
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
6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?