Skip to content

Instantly share code, notes, and snippets.

View solutelabs-savan's full-sized avatar

Savan Raval solutelabs-savan

  • India
View GitHub Profile
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render json: user.as_json(auth_token: user.authentication_token, email: user.email), status: :created
return
else
@solutelabs-savan
solutelabs-savan / db.rake
Created May 23, 2016 11:59 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@solutelabs-savan
solutelabs-savan / postgres.rake
Created May 23, 2016 12:37 — forked from owainlewis/postgres.rake
Backup task for Postgres
namespace :postgres do
desc 'Backup postgres database'
task :backup => :environment do
db_config = Rails.application.config.database_configuration[Rails.env]
backup_dir = '/home/deploy/backups'
outfile = "#{ backup_dir }/#{ Rails.env }_#{ DateTime.now.strftime("%Y%m%d_%H%M%S.sql.gz") }"
cmd = "pg_dump -h localhost -U #{ db_config['username'] } #{ db_config['database'] } | gzip -c > #{outfile}"
puts "Making database backup..."
@solutelabs-savan
solutelabs-savan / gist:d742e74718d8400edc942ba5441e3dca
Created June 1, 2016 12:18 — forked from mattconnolly/gist:4158961
RSpec basic authentication helper module for request and controller specs
module AuthHelper
def http_login
user = 'username'
pw = 'password'
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user,pw)
end
end
module AuthRequestHelper
#