Allow user to creates named auth keys with token

This commit is contained in:
Thibault Jouan
2015-05-04 04:34:13 +00:00
parent 7d1274cbb3
commit 763c9789ec
12 changed files with 174 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
class KeysController < ApplicationController
before_filter :set_key, only: %i[show edit update destroy]
def index
@keys = current_user.keys
end
def show
end
def new
@key = current_user.keys.new
end
def create
@key = current_user.keys.build key_params
if @key.save
redirect_to action: :index
else
render :new
end
end
def edit
end
def update
if @key.update_attributes key_params
redirect_to action: :index
else
render :edit
end
end
def destroy
@key.destroy
redirect_to keys_path
end
private
def set_key
@key = current_user.keys.find(params[:id])
end
def key_params
params.require(:key).permit :name
end
end