Skip to content

Instantly share code, notes, and snippets.

class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'

Web fonts are pretty much all the rage. Using a CDN for font libraries, like TypeKit or Google Fonts, will be a great solution for many projects. For others, this is not an option. Especially when you are creating a custom icon library for your project.

Rails and the asset pipeline are great tools, but Rails has yet to get caught up in the custom web font craze.

As with all things Rails, there is more then one way to skin this cat. There is the recommended way, and then there are the other ways.

The recommended way

Here I will show how to update your Rails project so that you can use the asset pipeline appropriately and resource your files using the common Rails convention.

@oojikoo-gist
oojikoo-gist / application_controller.rb
Last active August 29, 2015 14:16 — forked from Sujimichi/application_controller.rb
rails: rescue_from_routing_error
class ApplicationController < ActionController::Base
...
#Problem:
#In rails 3.0.1+ it is no longer possible to do this anymore;
# rescue_from ActionController::RoutingError, :with => :render_not_found
#
#The ActionController::RoutingError thrown is not caught by rescue_from.
#The alternative is to to set a catch-all route to catch all unmatched routes and send them to a method which renders an error
#As in http://techoctave.com/c7/posts/36-rails-3-0-rescue-from-routing-error-solution
@oojikoo-gist
oojikoo-gist / Gemfile example
Last active August 29, 2015 14:16
rails: Gemfile for minitest
group :development, :test do
gem "minitest", "> 4.0"
gem 'minitest-rails'
gem "minitest-rails-capybara"
gem "minitest-focus"
gem "minitest-colorize"
gem "capybara-webkit"
gem "launchy"
gem "pry-rails"
gem "pry-doc"
require 'minitest/autorun'
require 'pry-rescue/minitest'
require 'capybara'
require 'capybara/dsl'
require 'capybara/poltergeist'
require 'minitest/colorize'
Capybara.register_driver :poltergeist do |app|
@oojikoo-gist
oojikoo-gist / 0_reuse_code.js
Last active August 29, 2015 14:15
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@oojikoo-gist
oojikoo-gist / registrations_controller.rb
Last active August 29, 2015 14:15 — forked from jwo/registrations_controller.rb
rails: devise reset api
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
@oojikoo-gist
oojikoo-gist / backbonejs_handson.md
Last active August 29, 2015 14:14 — forked from riseshia/backbonejs_handson.md
backbone: handson

Backbone.js handsOn

  • Ruby : 2.2.0
  • Rails : 4.1.7
  • backbone-on-rails : 1.1.2.0
  • jQuery : 1.11.2

Preparing

Create App

@oojikoo-gist
oojikoo-gist / edge_template.rb
Last active September 14, 2015 14:38 — forked from marocchino/edge_template.rb
rails: template and ember handson
# This script is used with the Ruby on Rails' new project generator:
#
# rails new my_app -m http://emberjs.com/edge_template.rb
#
# For more information about the template API, please see the following Rails
# guide:
#
# http://edgeguides.rubyonrails.org/rails_application_templates.html
# Install required gems