| div.section .gist .gist-file .gist-data pre{ | |
| font-family: consolas, monospace, sans-serif !important; | |
| -moz-border-radius: 8px; | |
| -moz-border-radius-bottomleft: 0; | |
| -moz-border-radius-bottomright: 0; | |
| -webkit-border-radius: 8px; | |
| -webkit-border-bottom-left-radius: 0; | |
| -webkit-border-bottom-right-radius: 0; | |
| overflow: auto !important; | |
| color: #c2c2c2; |
| source 'http://rubygems.org' | |
| gem 'rspec' | |
| gem 'capybara', :git => 'https://github.com/jnicklas/capybara.git' | |
| gem 'launchy' | |
| gem 'ruby-debug19' |
| require 'active_record' | |
| ActiveRecord::Base.logger = Logger.new(STDERR) | |
| ActiveRecord::Base.colorize_logging = false | |
| ActiveRecord::Base.establish_connection( | |
| :adapter => "sqlite3", | |
| :dbfile => ":memory:" | |
| ) |
| # Parses YouTube URLs directly or from iframe code. Handles: | |
| # * Address bar on YouTube url (ex: http://www.youtube.com/watch?v=ZFqlHhCNBOI) | |
| # * Direct http://youtu.be/ url (ex: http://youtu.be/ZFqlHhCNBOI) | |
| # * Full iframe embed code (ex: <iframe src="http://www.youtube.com/embed/ZFqlHhCNBOI">) | |
| # * Old <object> tag embed code (ex: <object><param name="movie" value="http://www.youtube.com/v/ZFqlHhCNBOI">...) | |
| /(youtu\.be\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&"'>]+)/ | |
| $5 #=> the video ID | |
| # test it on Rubular: http://rubular.com/r/eaJeSMkJvo |
| 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=>201 | |
| return | |
| else |
| require "rubygems" | |
| require 'sinatra' | |
| require "aws/s3" | |
| get '/' do | |
| return %Q{ | |
| <form action="upload" method="post" accept-charset="utf-8" enctype="multipart/form-data"> | |
| <div> | |
| <input type="file" name="file" value="" id="file"> | |
| </div> |
| <% flash.each do |type, message| %> | |
| <div class="alert <%= bootstrap_class_for(type) %> fade in"> | |
| <button class="close" data-dismiss="alert">×</button> | |
| <%= message %> | |
| </div> | |
| <% end %> |
| # Ignore static version of the site (used to upload error pages to S3 for Heroku errors) | |
| /out |
#Simple Authentication with Bcrypt
This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.
The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).
You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault
##Steps