TAG_rel_2-0-0_RC2をfreezeしたプロジェクトでDBを作成しようとしたところ、下記のエラーが。

   1  $ sudo rake db:create RAILS_ENV='production'
   2  (in /usr/local/foo)
   3  rake aborted!
   4  undefined method `whiny_protected_attributes=' for ActiveRecord::Base:Class
   5  
   6  (See full trace by running task with --trace)

同じことを言っている人がrubyonrails.comのコメントにもいて、ちゃんとJeremy Kemperが返事を書いています。
http://documentation.rubyonrails.com/2007/11/9/rails-2-0-release-candidate-1#comment-17936

delete the whiny_protected_attributes setting from your environement. It was in the preview release but is not in the release candidate, so if you generated an app with the preview and are now upgrading it, you’ll need to remove that line.

というわけでconfig/environments/production.rb内で下記をコメントアウトしました。

   1  # Disable raising errors when mass-assigning to a protected attribute
   2  # config.active_record.whiny_protected_attributes = false

すんなり解決。

posted by Png satoko on Mon 3 Dec 2007 at 11:23

RaPT は、Ruby on Railsのプラグインを管理するためのツールです。

RaPT is a replacement for the plugin script included with the Rails distribution. It's a little more fault-tolerant and featured than the default plugin script. The main additional feature is the ability to search for Rails plugins from the command line.

なんとなく、名前がdebianのaptに似てると思うのは僕だけでしょうか。

以前から、RailsプラグインにもRubyGemsに相当するような パッケージ管理ツールがほしいと思っていたのですが、 これを使えば目的を達することができるかも。

インストール

RaPT自体はRubyGemsとして提供されています。

   1  % sudo gem install rapt

おなじみのコマンドですね。これでOK。

使い方

   1  % rapt -h
   2  Usage: rapt [OPTIONS] command
   3  Rails plugin manager.
   4  
   5  GENERAL OPTIONS
   6    -r, --root=DIR          Set an explicit rails app directory.
   7                            Default: /home/takiuchi/blog
   8    -s, --source=URL1,URL2  Use the specified plugin repositories instead
   9   of the defaults.
  10    -v, --verbose           Turn on verbose output.
  11    -h, --help              Show this help message.

サブコマンド

   1  discover       Discover plugin repositories.
   2  list           List available plugins.
   3  search         Search for available plugins.
   4  about          Show basic info about a plugin.
   5  install        Install plugin(s) from known repositories or URLs.
   6  update         Update installed plugins.
   7  remove         Uninstall plugins.
   8  source         Add a plugin source repository.
   9  unsource       Remove a plugin repository.
  10  sources        List currently configured plugin repositories.
  11  pack:install   Install plugins from plugin pack file or URL
  12  pack:uninstall Uninstall plugins from plugin pack file or URL
  13  pack:about     Display plugin pack information

使用例

長くなったので、 Click to toggle display Example.

Install a plugin:

   1  % rapt install continuous_builder

Install a plugin from a subversion URL:

   1  % rapt install http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder

Install a plugin and add a svn:externals entry to vendor/plugins

   1  % rapt install -x continuous_builder

Show information about the acts_as_chunky_bacon plugin:

   1  % rapt about acts_as_chunky_bacon

List all available plugins:

   1  % rapt list

List plugins in the specified repository:

   1  % rapt list --source=http://dev.rubyonrails.com/svn/rails/plugins/

Search available plugins:

   1  % rapt search "authentication"

Discover and prompt to add new repositories:

   1  % rapt discover

Discover new repositories but just list them, don't add anything:

   1  % rapt discover -l

Add a new repository to the source list:

   1  % rapt source http://dev.rubyonrails.com/svn/rails/plugins/

Remove a repository from the source list:

   1  rapt unsource http://dev.rubyonrails.com/svn/rails/plugins/

Show currently configured repositories:

   1  % rapt sources

Show the options for the list command:

   1  % rapt list -h

Install a plugin pack:

   1  % rapt pack:install http://opensource.agileevolved.com/pluginpacks/standard.pluginpack

View plugin pack meta data:

   1  % rapt pack:about http://opensource.agileevolved.com/pluginpacks/standard.pluginpack

posted by Png genki on Sun 2 Dec 2007 at 03:03

Creating OpenSearch plugins for Firefox を参考に、このブログの検索機能をOpenSearchプラグインに対応しました。

FirefoxやFlock、CaminoなどのMozilla系のブラウザの検索バーから、 サイト内を検索することができます。

posted by Png genki on Sun 2 Dec 2007 at 00:38

aptitude update したらこんなエラーメッセージが出たので、対処法をメモ。

/etc/apt/apt.conf.d/70debconf

   1  APT::Cache-Limit 100000000;

後は普通に aptitude update でOK。

posted by Png genki on Sat 1 Dec 2007 at 00:15
30th Fri

Rails 2.0 RC2

Rails 2.0のRC2がリリースされましたね。正式リリースも間近のようです。

Rails 2.0: Release Candidate 2

After another batch of fixes, tweaks, and buckets of polish, we’ve prepared the hopefully last step before 2.0 can go final: Release Candidate 2. If nothing major pops up, expect the final version to land within the next week or two at the most.

早速、このブログもRails 2.0 RC2にアップデートしてみました。 今まではRC1でしたが、特に問題も無く、すんなりと移行できました。

posted by Png genki on Fri 30 Nov 2007 at 07:07

acts_as_searchable is one of the most useful plugins which's enabling us to add a fulltext search feature to our models/resources easily.

Unfortunately, it is lacking an interface to the features of searching by similarity provided by HyperEstraier.

So I wrote some codes to add an interface to exploit it. This is acts_as_searchable_with_similarity.

How to use?

Here is an example.

app/models/article.rb

   1  class Article < ActiveRecord::Base
   2    acts_as_searchable
   3  end
   4  
   5  Article.similarity_search(target_article,  :limit => 5)

posted by Png genki on Thu 29 Nov 2007 at 23:37

acts_as_searchable は、 HyperEstraier を使って簡単に全文検索を行うことができる、 非常に便利なRailsプラグインです。 しかし、HyperEstraierが提供する類似検索機能を使うインターフェイスが 用意されていないようだったので、類似検索機能を付け足しました。

オリジナルの acts_as_searchable に対する差分はこちらにあります。

使い方

まずは、オリジナルと同様に検索対象のモデルに acts_as_searchableを書き加えます。 必要に応じて適切なオプションを指定してください。

app/models/article.rb

   1  class Article < ActiveRecord::Base
   2    acts_as_searchable

あとは、以下のように類似検索を行うだけです。

   1  Article.similarity_search(target_article, :limit => 5)

ちなみに、このブログの類似記事表示機能でも使用しています。

MIT LICENSE に基づいて、修正版を再配布します。

  1. このソフトウェアを誰でも無償で無制限に扱って良い。但し、著作権表示および本許諾表示を、ソフトウェアのすべての複製または重要な部分に記載しなければならない。
  2. 作者または著作権者は、ソフトウェアに関してなんら責任を負わない。

修正部分のコードもMIT LICENSEとします。

posted by Png genki on Thu 29 Nov 2007 at 23:08

標準のrakeタスクが便利です。最近教えてもらった/気づいたものもあるので一覧にしてみました。
db:create, db:reset, db:version, rake:routesなんかは最近知ったやつです。
時々rake --taskで便利なタスクがないか探してみるのもいいかもしれません。

   1  rake db:create  
   2  rake db:migrate VERSION=1  
   3  rake db:reset
   4  rake db:test:clone  
   5  rake db:version
   6  rake rails:freeze:edge REVISION=8220  
   7  rake routes  

よく見たらこんなのもあった。使ってみよう。

   1  rake test:uncommitted          # Test changes since last checkin (only Subversion)

posted by Png satoko on Thu 29 Nov 2007 at 07:36

SyslogLogger

SyslogLogger is a Logger replacement that logs to syslog. It is almost drop-in with a few caveats.

SyslogLoggerを使うと、railsのログを syslog に記録するように する事ができます。

インストール方法

   1  % sudo gem install SyslogLogger

普通に rubygems としてインストールできます。 続いて、アプリケーションの設定を行います。

config/environments/production.rb

   1  # SyslogLogger
   2  require 'syslog_logger'
   3  RAILS_DEFAULT_LOGGER = SyslogLogger.new 'appname'

appnameはアプリケーションを識別する名前に置き換えてください。

さらに、syslogの設定を行います。 rootになって以下の記述を書き加えます。

/etc/syslog.conf

!appname
*.*     /var/log/appname.log

修正が済んだら、空の/var/log/appname.logファイルを作成して syslogdを再起動します(例えば killall -HUP syslogd

これで、以後は /var/log/appname.log 及び /var/log/syslog に ログデータが書き出されるようになります。

posted by Png genki on Thu 29 Nov 2007 at 05:28

Hash#sliceが欲しい をさらに拡張。

指定したキーを取り除いたHashを返すHash#exceptを追加。 併せて、既存のHash#sliceHash#onlyに改名してみました。

hash_ext.rb

   1  class Hash
   2    def only(*args)
   3      args = *args if args[0].is_a? Array
   4      args.inject({}){|hash, key| hash[key] = self[key]; hash}
   5    end
   6    
   7    def except(*args)
   8      args = *args if args[0].is_a? Array
   9      args.inject(dup){|hash, key| hash.delete(key); hash}
  10    end
  11  end

使い方:

   1  cond = params.only :year, :month, :day
   2  ma = MonthlyArchive.find :all, :conditions => cond.except(:day)

posted by Png genki on Thu 29 Nov 2007 at 03:08