Skip to content

Instantly share code, notes, and snippets.

# A simple app that implements a naive session-based login, to demonstrate the problems with testing sessions in Sinatra.
require 'rubygems'
require 'sinatra/base'
class LoginApp < Sinatra::Base
enable :sessions
get '/' do
... .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*\.html)$ file.php?target=$1 [QSA,L]
#敢えてファイルが存在するときで、末尾に.htmlが付くファイルの場合のみリライトさせる
</IfModule>
@a2ikm
a2ikm / nested_const.rb
Created September 9, 2011 07:06
Get or set nested constant
#!/usr/bin/ruby
class Object
# copied from http://blog.udzura.jp/2010/03/08/petit-hacking-about-const_get/
def self.nested_const_get(name)
stack = (name.is_a?(Array)) ? name : name.to_s.split("::")
klass = Object
while const = stack.shift
klass = klass.const_get(const)
end
@dallas
dallas / rails31init.md
Created September 11, 2011 05:22 — forked from docwhat/rails31init.md
Rails 3.1 with Rspec, Factory Girl, Haml, Simple Form, Database Cleaner, Spork, and Guard

Install Rails 3.1

gem install rails

generate new app, skipping Test::Unit file generation

rails new my_app -T

Set up Gemfile

@jeffreyiacono
jeffreyiacono / Rakefile
Created February 8, 2012 20:15
rake task for precompiling assets using sprockets within a sinatra app + view helpers
require 'rubygems'
require 'bundler'
Bundler.require
require './application'
namespace :assets do
desc 'compile assets'
task :compile => [:compile_js, :compile_css] do
end
@shamil614
shamil614 / attachment.rb
Created November 2, 2012 16:12
Carrierwave Attachment Uploader with AWS and Zencoder.
class Attachment < ActiveRecord::Base
belongs_to :attachable, :polymorphic => true
mount_uploader :item, AttachmentUploader
# background the storage of files to AWS and processing
# makes for fast uploads!
store_in_background :item
attr_accessible :item
before_save :update_attachment_attributes
@tkawa
tkawa / i18n_exception_handler.rb
Created February 3, 2013 12:36
Railsでlocaleの翻訳が見つからなかったとき、“translation missing”はログに出して、viewにはhumanizeした文字列を出す
# config/initializers/i18n_exception_handler.rb
I18n.exception_handler = ->(exception, locale, key, options) do
if exception.is_a?(I18n::MissingTranslation)
Rails.logger.warn exception.message if Rails.env.development?
key.to_s.split('.').last.humanize
else
raise exception
end
end
@ideasasylum
ideasasylum / pre-commit
Created March 7, 2013 21:49
A pre-commit Git hook for preventing commits containing focus: true, debugger, binding.pry etc Based on a blog post I wrote http://jamie.ideasasylum.com/2013/02/preventing-the-stupid-mistakes-like-committing-focustrue/ (which in turn was based on someone else's script). This version allows you to easily setup new rules at the head of the script
#!/usr/bin/env ruby
spec_hits = []
checks = {
'_spec\.rb$' => ['focus:[:space:]*true'],
'\.rb$' => ['binding\.pry', 'debugger']
}
# Find the names of all the filenames that have been (A)dded (C)opied or (M)odified
filenames = `git diff --cached --name-only --diff-filter=ACM`.split("\n")

2013 年の新卒研修メニュー

Rails Tutorial

目的

  • 2013 年にモダンな方法で一通り Web アプリケーションを自分一人で作れるようになってもらう
  • 作る過程で Web 開発で必要とされるアプリケーションレイヤのスキルセットを身につけてもらう

教科書