gem install rails
rails new my_app -T
# 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> | |
#!/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 |
require 'rubygems' | |
require 'bundler' | |
Bundler.require | |
require './application' | |
namespace :assets do | |
desc 'compile assets' | |
task :compile => [:compile_js, :compile_css] do | |
end |
基礎知識
読み物系
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 |
# 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 |
#!/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") |