{{toc}}
- Use UTF-8. It’s 21 century, 8bit encodings dead now.
- Use 2 space indent, not tabs
- Use Unix-style line endings
- Keep lines not longer than 80 chars
module MyApp | |
class Application < Rails::Application | |
require Rails.root + 'lib/custom_public_exceptions' | |
config.exceptions_app = CustomPublicExceptions.new Rails.public_path | |
end | |
end |
# Patch for ransack (https://github.com/ernie/ransack) to use scopes | |
# Helps migrating from Searchlogic or MetaSearch | |
# Place this file into config/initializer/ransack.rb of your Rails 3.2 project | |
# | |
# Usage: | |
# class Debt < ActiveRecord::Base | |
# scope :overdue, lambda { where(["status = 'open' AND due_date < ?", Date.today]) } | |
# end | |
# | |
# Ransack out of the box ignores scopes. Example: |
#paste this code in your ransack.rb initializer | |
#if you want to use scopes on search or sort please use Class.ransack_with_scopes instead of Class.search | |
Ransack::Adapters::ActiveRecord::Base.class_eval do | |
def ransack(params = {}, options = {}, scope_used_on_sort = false) | |
Ransack::Search.new(self, params, options, scope_used_on_sort) | |
end | |
def ransack_with_scopes(params = {}, options = {}) | |
scope_used_on_sort = false | |
ransack_scope = self | |
ransack_params = {} |
Originally published in June 2008
When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.
To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.
Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.
require 'action_dispatch/middleware/static' | |
module Middleware | |
class FileHandler < ActionDispatch::FileHandler | |
def initialize(root, assets_path, cache_control) | |
@assets_path = assets_path.chomp('/') + '/' | |
super(root, cache_control) | |
end | |
def match?(path) |
#!/usr/bin/env ruby | |
require 'gosu' # gem install gosu | |
$width, $height = 200, 200 | |
$number_of_v_lines,$number_of_h_lines = 10, 10 | |
$chars = ('a'..'z').to_a | |
class Entity | |
def initialize(x,y,vel, win) | |
@pos, @vel = {x:x, y:y}, vel |
server { | |
listen 443 ssl spdy default_server; | |
server_name example.com; | |
ssl_certificate /etc/ssl/certs/my.ssl.crt; | |
ssl_certificate_key /etc/ssl/private/my.ssl.key; | |
root /mysite/current/public; | |
passenger_enabled on; |
gem 'kaminari' # Pagination |
# Because we have some old legacy users in the database, we need to override Devises method for checking if a password is valid. | |
# We first ask Devise if the password is valid, and if it throws an InvalidHash exception, we know that we're dealing with a | |
# legacy user, so we check the password against the SHA1 algorithm that was used to hash the password in the old database. | |
#SOURCES OF SOLUTION: | |
# http://stackoverflow.com/questions/6113375/converting-existing-password-hash-to-devise | |
# https://github.com/binarylogic/authlogic/blob/master/lib/authlogic/crypto_providers/sha512.rb | |
# https://github.com/plataformatec/devise/blob/master/lib/devise/encryptors/authlogic_sha512.rb | |
alias :devise_valid_password? :valid_password? | |
def valid_password?(password) |