vinistock/sail

View on GitHub
app/controllers/sail/profiles_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

require_dependency "sail/application_controller"

module Sail
  # ProfilesController
  #
  # This controller implements all profile related
  # APIs.
  class ProfilesController < ApplicationController
    def create
      respond_to do |format|
        format.js do
          @profile, @new_record = Sail::Profile.create_or_update_self(s_params[:name])
        end
      end
    end

    def switch
      respond_to do |format|
        format.js { Sail::Profile.switch(s_params[:name]) }
        format.json { Sail::Profile.switch(s_params[:name]) }
      end
    end

    def destroy
      respond_to do |format|
        format.js do
          @profile = Sail::Profile.find_by(name: s_params[:name]).destroy
        end
      end
    end

    private

    def s_params
      params.permit(:name, :locale)
    end
  end
end