ドメイン境界を越えてjsで通信する方法。

Introducing CrossFrame, a Safe Communication Mechanism Across Documents and Across Domains

たぶんShootingStarで使ってる方法と同じものだと思う。

posted by Png genki on Wed 28 Nov 2007 at 16:11

   1    map.resources :users
   2    map.resource :session

routes.rbに出てくる、map.resource。綴り間違い??とひそかに思っていたらちゃんとありました。
map.resourceについてヘルプを見てみます。

Creates named routes for implementing verb-oriented controllers for a singleton resource. A singleton resource is global to the current user visiting the application, such as a user‘s /account profile.

単数コントローラ名でパスを提供する場合に使えるようです。

  • a singular name is given to map.resource. The default controller name is taken from the singular name.
  • To specify a custom plural name, use the :plural option. There is no :singular option
  • No default index, new, or create routes are created for the singleton resource controller.
  • When nesting singleton resources, only the singular name is used as the path prefix (example: 'account/messages/1')
  • 単数形を使ったリソースを提供できます
  • :pluralオプションを使えば、複数を使うこともOK。:singularオプションはありません。
  • index, new, createのroutesは作られません
  • 入れ子で単数形resourceを使っている場合、prefixには単数形が使われます
    ex 'account/messages/1'

ヘルプにある生成されるというパスと私の環境のrake routesで表示されるパスが異なるようなので使用しているrailsで確認することが必要があるように思います。

posted by Png satoko on Wed 28 Nov 2007 at 05:51

ので作ってみた。

hash_ext.rb

   1  class Hash
   2    def slice(*args)
   3      args = *args if args[0].is_a? Array
   4      args.inject({}){|hash, key| hash[key] = self[key]; hash}
   5    end
   6  end

使い方:

   1  conditions = params.slice :year, :month, :day

posted by Png genki on Wed 28 Nov 2007 at 04:16

Rails 2.0(RC1)でチェックしてみたところ、以下のような構文で migration コードの生成時に追加・削除を行うcolumnを指定できるようです。

   1  % ./script/generate migration add_fullname_to_users fullname:string

この結果、生成生成されるコードは以下の通り。

db/migrate/XXX_add_fullname_to_users.rb

   1  class AddFullnameToUsers < ActiveRecord::Migration
   2    def self.up
   3      add_column :users, :fullname, :string
   4    end
   5  
   6    def self.down
   7      remove_column :users, :fullname
   8    end
   9  end

ちょっと前まで、add_xxxx_to_yyyy で yyyyテーブルにxxxxカラムを 追加するという感じの挙動をしていたのですが、それは無くなったみたいですね。 まだRC1なので最終的にどういう形に落ち着くか分かりませんが、 なかなかいい感じです。

posted by Png genki on Wed 28 Nov 2007 at 02:07

今まできちんと動作していなかった、DailyとMonthlyのアーカイブ表示の 実装を修正しました。

記事一覧表示画面の上部に表示されているカレンダーからアクセスできます。

よろしくお願いします。

posted by Png genki on Tue 27 Nov 2007 at 17:44

そうじゃないか。

posted by Png genki on Tue 27 Nov 2007 at 09:05

Railsのroutes.rbでNamed Routeを利用するときに、 メソッド名の競合などで通常は使えない名前をどうしても 利用したい場合、以下のように記述することで利用できます。

config/routes.rb

   1  map.send :method_missing, :touch, 'foo/:id/touch', :action => 'touch'

メソッドがすでに定義されているため、method_missing が呼ばれなくなっている状態を無理やり回避しています。

posted by Png genki on Mon 26 Nov 2007 at 15:02

Railsのプラグインは、簡単に作れるせいか、おかしな、 というか、随分てきとうな名前のものが多いのですが、最近は 一時期流行していたacts_as_xxxable系のプラグインに代わり、 xxx_fuという名前のプラグインが増えてきました。

timezone_fu

  • Timezone conversion with TZInfo as easy as has_timezone :fields => [ :start_datetime, :end_datetime].
  • 美しい世界地図が印象的

enum_fu

  • Make an integer field as an enum typed one

resource_fu

  • A collection of hacks that make nested and polymorphic resources less painful.

Bundle-fu

  • CSS/JS asset bundling in 10 seconds or less!
  • Rails-2.0 Readyだ!

mimetype-fu

  • Get the content type / mime type of a file. Great to use with attachment_fu or to validate Flash uploads.

Attachment Fu

  • Rewrite of acts_as_attachment
  • Amazon S3も使える

Permalink Fu

  • Create permalinks from attributes

BackgroundFu

  • Threadを使って時間がかかる処理を行う

さて、次に流行するのはどんな名前でしょう。

更新履歴

  • 2007/12/11 BackgroundFuを追加
posted by Png genki on Mon 26 Nov 2007 at 05:43

記事の引越しから漏れていたのでサルベージ。

zsh用のscript/generateおよびscript/destroyの補完関数です。 以下のスクリプトを.zshrcなどに書いておけば、 ./script/generateに続けてTABキーを押す事で generatorの入力を補完できます。

~/.zshrc

   1  _generate () {
   2    if [ ! -f .generators ]; then
   3      ./script/generate --help | grep '^  [^ ]*: ' | sed 's/[^:]*:/compadd/' | sed 's/\,//g' > .generators
   4    fi
   5    `cat .generators`
   6  }
   7  
   8  compdef _generate generate
   9  compdef _generate destroy

RubyGems、Plugin、BuildInの3種類のgeneratorを検出して補完します。 検出動作が重いので、カレントディレクトリにキャッシュファイルを作成して 2度目以降の補完を高速化しています。 generatorを追加した場合など、キャッシュを無効化したい場合は

   1  $ rm .generators

でキャッシュファイルを削除してください。

補完が重くても余計なファイルが生成されるよりはマシ、 という場合はこちらをどうぞ。

   1  _generate () {
   2    `./script/generate --help | grep '^  [^ ]*: ' | sed 's/[^:]*:/compadd/' | sed 's/\,//g'`
   3  }
   4  
   5  compdef _generate generate
   6  compdef _generate destroy

誰かが作らないかなあ、と思って待っていたのですが、 なかなか出て来ないので自分で作りました。 もっと良いものがあったら教えていただけると嬉しいです。

posted by Png genki on Mon 26 Nov 2007 at 05:05

ORF 2007 で地下展の話を聞いて興味深かったので、 日本科学未来館に行ってきました。

ticket

ボストーク湖 の展示が興味深かったです。 ほかにもいくつか面白いキーワードを採取できました。

それから、お土産店で蛍石と方解石をGet。

蛍石(左)と方解石(右)

rock

どちらの鉱石も、レンダリングアルゴリズムを考える上では、 興味深い光学特性を持っています。

posted by Png genki on Mon 26 Nov 2007 at 04:31