rails

Railsプラグイン ez_where がクソ便利

Railsの検索画面などを作るときに、入力パラメータに合わせて conditionsを変更したい場合等が多数あると思うけどそういう場合は ez_whereがめちゃ便利インストール ./script/plugin install http://opensvn.csie.org/ezra/rails/plugins/dev/ez_where/ User…

rake db:migrateでversionが固定される

なんか rake db:migrateで versionが2に固定される。VERSION=10とかに上げて 次にrake:migrateとかやると、また VERSION 2に戻される。問題のコード rails-2.0.2/lib/tasks/databases.rake desc "Migrate the database through scripts in db/migrate. Targe…

id:komagataさんがおもしろい試みをはじめたようです

次回も駒形先生の作品にご期待ください。

uninitialized constant CGI::Session::ActiveRecordStore

rails/gettext と session: active_record_store を併用する環境で、 uninitialized constant CGI::Session::ActiveRecordStore ってエラーが出てたんだけど、rails/gettext を requireする前に active_record を require しなければならないっぽい。 rails/…

ActiveRecordをSequelっぽく扱う

module ActiveRecordHelper def each(opts={}) rows = find(:all, opts) while rows.any? rows.each{|v| yield v} conditions = if opts.key? :conditions _conditions = opts[:conditions].clone _conditions.first.insert(0, 'id > ? and ') _conditions.i…

mod_rails がリリースされた

インストールは gem install passenger gemdir/passenger/doc/Users guide.txt に説明があるのでその通り入れたら無事起動。 session :off render :text => 'hello' とやるだけのRailsアプリケーションを productionモードでベンチマークを取ってみた。 mod_…

merbのevented_mongrelが無言で落ちる

ので、一旦普通のmongrelに戻した。

acts_as_searchable の reindex!がメモリを使いすぎるので修正

acts_as_searchable_col-0.1.1/lib/acts_as_searchable_col.rb def reinex + id = 0 + while rows = find(:all, :conditions => ['id > ?', id], :limit => 1000, :order => :id ) + break unless rows.any? + rows.each{|r| r.update_index(true)} + id = r…

merb with evented_mongrel

このまえ merb のバージョンを上げたのでソースを見てみたら merb.rbに if ENV['SWIFT'] require 'swiftcore/swiftiplied_mongrel' ... elsif ENV['EVENT'] require 'swiftcore/evented_mongrel' ... elsif ENV['PACKET'] require 'packet_mongrel' ... else…

productionでbacktraceを表示する

application.rb の ApplicationController 内に以下を追加 def log_error(exception) if RAILS_ENV == 'production' @bt = clean_backtrace(exception) end end public/500.htmlに以下を追加 <%=h @bt.inspect %>

restful

いまさらながら Rails 2.x のrestful Rails 1.x 機能 Verb Path Method Param 一覧 GET /book index 詳細 GET /book/show/1 show :id => 1 新規作成画面 GET /book/new new 新規作成実行 POST /book/create create 更新画面 GET /book/edit/1 edit :id => 1 …

merbのcookie ではまる

merbの0.4.1を使ってたんだけど set_cookieのコードが以下 # File lib/merb/mixins/controller.rb, line 140 140: def set_cookie(name, value, expires) 141: (headers['Set-Cookie'] ||='') << (Merb::Const::SET_COOKIE % [ 142: name.to_s, 143: escape(…

Mobile on Ralsで キャリアIPの更新を Test::Unit でテストする

ちゃんと過不足のIPも表示してくれる、いつ使えなくなるかはわからないけど。 require 'open-uri' class CarierIpTest < ActiveSupport::TestCase # Replace this with your real tests. @@SOFTBANK_URL = 'http://developers.softbankmobile.co.jp/dp/tech_…

OpenIDに対応する

忙しいので後で書く

ニコニコ動画のflvをmp3に変換

#!/usr/bin/ruby require 'rubygems' require 'nicovideo' Nicovideo.new('自分のメアド', '自分のパスワード').login.watch(ARGV.first) {|v| File.open("#{ARGV.first}.flv", "wb") {|f| f.write v.flv } } and system "ffmpeg -y -i #{ARGV.first}.flv -a…

Rails2.x + ruby-gettext

基本komagataさんのやりかた通りにやる http://p0t.jp/mt/archives/2007/06/pot_po.htmlrakutoさんのところを見て erb に対応する http://rakuto.blogspot.com/2008/01/ruby-ruby-gettext-1100eruby.html GetText::ErbParser.init(:extnames => ['.rhtml', '…