1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Rails】application_controller.rbについて

Last updated at Posted at 2025-04-30

記事概要

Ruby on Railsのapplication_controller.rbについて、まとめる

前提

  • Ruby on Railsでアプリケーションを作成している

基本情報

ファイルパス

app/controllers/application_controller.rb

記載方法

[コントローラー名]_controller.rbを、参照

処理概要

すべてのコントローラーが継承しているファイル
ここに処理を記述しておくことで、すべてのコントローラーで共通となる処理を作ることができる

Image from Gyazo

まとめ

authenticate_or_request_with_http_basicメソッド

Basic認証を実装するために使用する
使用方法は、こちらを参照

# 'admin'というユーザー名と、'password'というパスワードでBasic認証できるように設定
authenticate_or_request_with_http_basic do |username, password|
  username == 'admin' && password == 'password'
end

Ruby on Railsまとめ

コントローラー

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?