Skip to content

Instantly share code, notes, and snippets.

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 / 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"
@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

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.

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'
@oojikoo-gist
oojikoo-gist / cli_current_path
Created March 23, 2015 10:31
cli: grep current_path
pwd | grep -oh '[^\/]*$' | pbcopy
@oojikoo-gist
oojikoo-gist / application_controller.rb
Created March 25, 2015 15:59
rails: devise after_sign_in_path_for
def after_sign_in_path_for(resource)
current_user_path
end
@oojikoo-gist
oojikoo-gist / Gemfile_pattern.md
Created March 25, 2015 16:05
rails: Gemfile pattern

PATTERNS IN A RAILS GEMFILE

The majority of the projects used Rails defaults of Coffeescript, Sass, jQuery, and ERB

Only 37% of the projects used Bootstrap. I thought this number would be higher. It feels like every MVP out there starts with bootstrap.

Only 33% used HAML. I thought this number would be higher as well. I’m not a huge fan of HAML, but it seems like it’s the default templating language for most Rails developers I’ve worked with.

Around 1/3 of the projects turned off Turbolinks. I’ve spent a little bit of time using Turbolinks and while I’m not opposed to it, there are a handful of common practices that I was used to that didn’t work with Turbolinks. I suspect this was the case for many teams and just chose to turn it off out of frustration or interest in making progress elsewhere. I’ve definitely done this in the past when I just wanted to get something out the door.

@oojikoo-gist
oojikoo-gist / api_acronym.md
Last active August 29, 2015 14:17
rails: API acronym

easy fix for api-> API

ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.acronym 'API'
end

now You can write as below