With Currentuser.io, adding user management capabilities to your Ruby on Rails application is very simple.
Sign up to Currentuser.io, create a new project and retrieve Project ID from the Currentuser.io settings.
Add the currentuser-services gem in the Gemfile of your application:
# Gemfile gem 'currentuser-services'
Create an initializer:
# config/initializers/currentuser.rb Currentuser::Services.configure do |config| # Replace 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' with your Project ID config.project_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' end
Mount the Currentuser engine:
# config/routes.rb MyApplication::Application.routes.draw do currentuser end
Protect your actions:
# app/controllers/application_controller.rb class ApplicationController < ActionController::Base before_action :require_currentuser end
Your application is now protected: visitors need to sign up and sign in to access it.
You can call
currentuser_id in any action (or view) to identify the person currently using your application.