acts_as_taggable_on_steroids
はacts_as_taggableを強化したRailsプラグインで、非常に便利なので愛用しています。

しかし、find_tagged_withメソッドで OR を含む :conditions を指定すると、SQLの演算順序の問題で挙動がおかしくなります。
この問題を修正するには、以下のようにpluginコードを書き換えればOKです。

acts_as_taggable_on_steroids/lib/acts_as_taggable.rb

    def find_options_for_find_tagged_with(tags, options = {})
      tags = tags.is_a?(Array) ? TagList.new(tags.map(&:to_s)) : TagList.from(tags)
      options = options.dup

      return {} if tags.empty?

      conditions = []
      #conditions << sanitize_sql(options.delete(:conditions)) if options[:conditions]
      if options[:conditions]
        conditions << "(#{sanitize_sql(options.delete(:conditions))})"
      end

要は、オリジナルの :conditions を括弧で括って演算順序の問題が起きないようにしているわけですね。

posted by genki genki on Mon 5 Nov 2007 at 17:07 with 0 comments

Railsの設定は、config/environment.rbのなかで、

Rails::Initializer.run do |config|
  # Settings in config/environments/* take precedence over those specified here
  config.log_level = :debug

というような感じに記述します。

アプリケーション側からここで設定した値を参照したいという場合に、その方法が提供されている気がしたので、Rails::Initializerのソースを探してみたのですが、そのような手段は用意されていないようでした。

Railsのコアを書き換えるプラグインを書こうかと思ったのですが、ふと以下のように書けば問題が解決することに気がつきました。

Rails::Initializer.run do |config| $rails_config = config

あとはどこからでも、グローバル変数の$rails_configを介して、Railsの設定情報にアクセスすることが出来ます。

posted by genki genki on Mon 5 Nov 2007 at 16:27 with 0 comments
Contents rssrss
Leading Smart TV App Development Companies | USA | 4 Way Technologies
Apple TV Developer | TVOS Development | USA | 4 Way Technologies
光ファイバーを二次元振動させて走査するAR用ディスプレイ
因果の取り違え
Value Transformer
Swift2's defer for CoffeeScript
mongodb-3.0からcreateIndexのdropDupsが無くなったらしい
mongodb-3.0以降のWiredTigerの設定を動的に変更する方法
一般楕円の高速生成アルゴリズムへの道標
farro mantecatoのレシピ
Tags
railsbugplugintips
Comments rssrss
瀧内元気 瀧内元気: MacOS版は以下にあります genki/ViMouse 01/16 05:40
KingofSmack KingofSmack: Here also good reads for this mobile application d... 05/10 18:02
Spencer Spencer: You don't have to re-compile it, this version work... 04/08 07:15
staiano staiano: Any chance we can get a recompile for 10.9? 01/10 01:47
dsjf dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これでも出... 01/08 23:23
yoku0825 yoku0825: nkfの方が使いやすいですが、glibcに含まれているiconvの方が 確実にどの環境にも入っている... 06/11 07:03
falsefalse falsefalse: @tiancongxin try using this one https://github.com... 02/14 08:04
瀧内元気 瀧内元気: おお、チェックしてみます。thx! 12/24 05:23
Services from s21g
YOMU Web小説リーダー
Web小説を音声で楽しむ読み上げリーダー
補助探
公開されている補助金・助成金情報を集約し、条件に合う制度を探しやすくするサービスです。
jotter.me
個人開発者のためのホスティング一体型ノートサービス
ハンドミラー
iPhone向けの手鏡アプリ
ツイプロ(twpro)
Twitterプロフィールの高速検索エンジン