frontend/app/controllers/publickeys_controller.rb in meroku-2.0.2 vs frontend/app/controllers/publickeys_controller.rb in meroku-2.0.3
- old
+ new
@@ -25,17 +25,23 @@
# POST /publickeys
# POST /publickeys.json
def create
@publickey = Publickey.new(publickey_params)
@publickey.user = User.find_by_token(params[:token])
+ if !@publickey.user
+ (render :jsonapi_errors => [{
+ title: 'Invalid Authorization Token',
+ detail: 'Invalid token. Try logging in again.'
+ }]) and return
respond_to do |format|
if @publickey.save
format.html { redirect_to @publickey, notice: 'Publickey was successfully created.' }
- format.json { render :show, status: :created, location: @publickey }
+ #format.json { render :show, status: :created, location: @publickey }
+ format.json { render jsonapi: @publickey }
else
format.html { render :new }
- format.json { render json: @publickey.errors, status: :unprocessable_entity }
+ format.json { render jsonapi_errors: @publickey.errors }
end
end
end
# PATCH/PUT /publickeys/1