0
0
Ruby on Railsframework~10 mins

Devise gem overview in Ruby on Rails - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add Devise to a Rails model for user authentication.

Ruby on Rails
class User < ApplicationRecord
  [1]
end
Drag options to blanks, or click blank then click option'
Ahas_secure_password
Binclude AuthModule
Cdevise :database_authenticatable, :registerable
Dextend Authentication
Attempts:
3 left
💡 Hint
Common Mistakes
Using has_secure_password instead of Devise's devise method.
Forgetting to include any authentication method in the model.
2fill in blank
medium

Complete the command to install Devise in a Rails app.

Ruby on Rails
bundle add [1]
Drag options to blanks, or click blank then click option'
Apundit
Bdevise
Comniauth
Dcancancan
Attempts:
3 left
💡 Hint
Common Mistakes
Adding unrelated gems like pundit or omniauth instead of Devise.
Forgetting to run bundle install after adding the gem.
3fill in blank
hard

Fix the error in the Devise route setup by completing the blank.

Ruby on Rails
Rails.application.routes.draw do
  [1] :users
end
Drag options to blanks, or click blank then click option'
Adevise_for
Bresources
Cget
Droot_to
Attempts:
3 left
💡 Hint
Common Mistakes
Using resources :users which does not set up Devise routes.
Using unrelated routing helpers like get or root_to.
4fill in blank
hard

Fill both blanks to add authentication checks in a controller.

Ruby on Rails
class PostsController < ApplicationController
  before_action [1] :authenticate_user!

  def index
    @posts = Post.all
  end
end
Drag options to blanks, or click blank then click option'
Aonly
Bexcept
Cskip_before_action
Dbefore_action
Attempts:
3 left
💡 Hint
Common Mistakes
Using skip_before_action which disables filters instead of adding them.
Confusing except with only.
5fill in blank
hard

Fill all three blanks to customize Devise's permitted parameters in ApplicationController.

Ruby on Rails
class ApplicationController < ActionController::Base
  before_action [1] :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.[2](:sign_up) do |user_params|
      user_params.permit(:email, :password, :password_confirmation, [3])
    end
  end
end
Drag options to blanks, or click blank then click option'
Abefore_action
Bpermit
C:username
Dpermit!
Eappend
Fsanitize
Attempts:
3 left
💡 Hint
Common Mistakes
Using permit! which allows all parameters and is unsafe.
Forgetting to check if: :devise_controller? to limit the filter.
Not permitting extra fields like :username.