Ruby on Rails

Authentication & Authorization

Devise (web sessions), has_secure_password, cookies, JWT (API authentication), Pundit, CanCanCan

22 Interview-Fragen·
Mid-Level
1

What is Devise in the Rails ecosystem?

Antwort

Devise is a flexible and complete authentication gem for Rails, built on Warden. It provides pre-configured modules to handle registration, login, password recovery, email confirmation, account locking and more. Devise is the most popular authentication solution in the Rails ecosystem due to its ease of integration and modularity.

2

What are the most commonly used Devise modules in a standard Rails application?

Antwort

Devise offers a modular architecture where each feature is a separable module. The most common modules are database_authenticatable (password authentication), registerable (registration), recoverable (password recovery), rememberable ('remember me' cookie), validatable (email and password validations), confirmable (email confirmation) and lockable (locking after failures).

3

How to protect a controller action so it is only accessible to logged-in users with Devise?

Antwort

Devise provides the authenticate_user! helper that can be used as a before_action in controllers. This filter checks if a user is logged in and redirects to the login page if not. It can be applied to all actions or limited with only or except. The helper name depends on the model (authenticate_admin! for an Admin model).

4

Which Devise helper allows accessing the currently logged-in user in a view or controller?

5

How to customize Devise views (login forms, registration, etc.) in a Rails application?

+19 Interview-Fragen

Meistere Ruby on Rails für dein nächstes Interview

Zugang zu allen Fragen, Flashcards, technischen Tests, Code-Review-Übungen und Interview-Simulatoren.

Kostenlos starten