render_to_string の罠

rails 4.1.4 render_to_string(:index, layout: false) # => "文字列" コンソールでの評価結果やメソッドの名前からは String が返ってくるように見えるでも実際は ActiveSupport::SafeBuffer が返ってくる render_to_string(:index, layout: false).class #…

追記

セリエBの制度が変更されるかもしれないリンクを修正

各国リーグの昇降格制度

把握していないところがあったのでまとめました。 2014年現在の制度です。 日本 J1の下位3クラブが自動降格。J2の上位2クラブが自動昇格。J2の3位から6位までのクラブでトーナメント形式のプレイオフを実施し勝者がJ1昇格。J2からJ3へ降格するクラブはJ3の上…

rails 4 で任意のテーブルのみ YAML で dump する

rails3 で任意のテーブルのみ dump できる fm_yaml_db(0.2.3) は、rails4 に対応していないのか動きません。rails4 に対応した yaml_db を使います。 gem 'yaml_db', github: 'jetthoughts/yaml_db', branch: 'rails4' dump するテーブルを返すメソッドをオ…

ポリモーフィックなコントローラー

Commentクラスはポリモーフィック関連 commentable を持ちます。 class Comment < ActiveRecord::Base belongs_to :commentable end class Cat < ActiveRecord::Base has_many :comments, :as => :commentable end class Dog < ActiveRecord::Base has_many …

FriendlyID 日本語の slug が変

日本語の文字列から slug を作成しようと、User.each(&:save) とすると"-f9f3789a-daec-4156-af1d-fab81aa16ee5" のような意味不明な slug が作成されてしまう。どうやら slug の生成に parameterize という ActiveSupportのメソッドを噛ませているらしく、…

Sqale を使ってみた

heroku の PostgreSQL 1万行制限に苦しんでいました。heroku は月額 $9 で10,000,000行まで増やせるのですが、コスパがちょっと・・・東京リージョンの VPS か PaaS を借りようかと悩んでいたところに登場したのがSqale の無料キャンペーン。さっそく飛びつ…

Padrino で new relic

1. new relic に登録します http://newrelic.com/ 2. newrelic.yml をダウンロードし編集、config/に配置します newrelic.yml app_name: AppName development: monitor_mode: false developer_mode: trueと編集しました。 3. Gemfile を編集します gem 'padr…

WARN DEPRECATION WARNING: Database connections will not be closed automatically...

WARN DEPRECATION WARNING: Database connections will not be closed automatically, please close your database connection at the end of the thread by calling `close` on your connection. For example: ActiveRecord::Base.connection.close. (calle…

2014ワールドカップブラジル大会の気候と時差

ブラジルの国土の大部分が南半球に位置するため、前回の南アフリカ大会と同様に大会の開催される6月の季節は冬です。しかし、6月の平均最高気温を比較してみると、南アフリカのケープタウンの16度に対し、ブラジルの首都ブラジリアは25.2度と、同じ冬でも10…

Padrinoで日本語をキャッシュさせようとするとEncoding::UndefinedConversionError

Padrino v. 0.10.5 class Project < Padrino::Application register Padrino::Cache enable :caching # 正常にキャッシュされる get :en, :cache => true do expires_in 30 Time.now.to_s end # Encoding::UndefinedConversionError get :ja, :cache => true…

Padrino で jpmobile

Gemfile gem "jpmobile" bundle installconfig.ru use Jpmobile::Rack::ParamsFilter use Jpmobile::Rack::Filter app.rb class Project < Padrino::Application use Jpmobile::Rack::MobileCarrier use Jpmobile::Rack::MobileCarrier を config.ru に書い…

Padrino の環境をロードする

padrino console でも良いのですが、まとまった処理を定期的に実行したいときは、 PADRINO_ENV = 'production' require File.expand_path("../config/boot.rb", __FILE__)

同名の関連先がある場合のincludes

ActiveRecord 3.1.1 でのおはなし。 class Game < ActiveRecord::Base belongs_to :home, :class_name => "Club", :foreign_key => 'home_id' belongs_to :away, :class_name => "Club", :foreign_key => 'away_id' end class Club < ActiveRecord::Base has…

No such file or directory - git ls-files (Errno::ENOENT)

Windows環境でmsysgitを入れてパスを通していないとき(インストール時にUse Git Bash onlyを選択)、Gemfileで gem "sinatra-assetpack", :git => "https://github.com/rstacruz/sinatra-assetpack.git" と、gitのリポジトリを指定すると、Git Bash以外からbu…

sinatra/padrino で静的ファイルの Cache-Control を指定する

configure do set :static_cache_control => [:public, :max_age => 60*60*24*30] end とすると、 - HTTP/1.1 200 OK Server: nginx/0.7.67 Date: Thu, 17 Nov 2011 16:42:08 GMT Content-Type: image/gif Connection: keep-alive Cache-Control: public, ma…

開発環境

はじめに現在の開発環境を書いておきます。 WindowsXP ruby 1.9.2p290 (2011-07-09) [i386-mingw32] Padrino v. 0.10.5 先日まではVistaで開発していたのですが、長らく壊れていたXPのPCが戻ってきたので、rubyの1.9.3 を入れようとしたらノートンがウイルス…