Skip to content

Instantly share code, notes, and snippets.

@dnlserrano
dnlserrano / api_controller.rb
Last active January 19, 2021 09:56
Custom Authentication Controllers
class ApiController < ApplicationController
# define which model will act as token authenticatable
acts_as_token_authentication_handler_for Login
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :null_session
respond_to :json
skip_before_filter :verify_authenticity_token, if: :json_request?
@dnlserrano
dnlserrano / create.json.jbuilder
Last active October 18, 2017 01:40
Custom Token Authentication SessionController with DRY Authenticatable Logout
json.success true
json.data do
json.auth_token @user.authentication_token
json.message "login successful"
end
@dnlserrano
dnlserrano / prepare-commit-msg
Created July 7, 2017 23:33
prepare-commit-msg git hook
#!/bin/sh
ticket=$(git symbolic-ref --short HEAD | sed 's/.*\/\([a-zA-Z]*\)-\([0-9]*\).*/JIRA \1-\2/g')
original_msg=$(cat $1)
echo "\n\n$ticket\n$original_msg" > $1
@dnlserrano
dnlserrano / pr.md
Created August 2, 2016 10:03 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@dnlserrano
dnlserrano / create.json.jbuilder
Last active August 29, 2015 13:57
Custom Token Authentication SessionsController
json.success true
json.data do
json.auth_token @user.authentication_token
end