CrossFrameという技術
ドメイン境界を越えてjsで通信する方法。
Introducin
たぶんShootingSt
ドメイン境界を越えてjsで通信する方法。
Introducin
たぶんShootingSt
1 map.resources :users 2 map.resource :session
routes.rbに出てくる、map.resour
map.resour
Creates named routes for implementi
ng verb-orien ted controller s for a singleton resource. A singleton resource is global to the current user visiting the applicatio n, such as a user‘s /account profile.
単数コントローラ名でパスを提供する場合に使えるようです。
- a singular name is given to map.resour
ce. 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/me
ssages/1')
ヘルプにある生成されるというパスと私の環境のrake routesで表示されるパスが異なるようなので使用しているrailsで確認することが必要があるように思います。
ので作ってみた。
hash_ext.r
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
Rails 2.0(RC1)でチェックしてみたところ、以下のような構文で migration コードの生成時に追加・削除を行うcolumnを指定できるようです。
1 % ./script/generate migration add_fullna me_to_user s fullname:s tring
この結果、生成生成されるコードは以下の通り。
db/migrate
1 class AddFullnameToUsers < ActiveReco rd::Migrat ion 2 def self.up 3 add_column :users, :fullname, :string 4 end 5 6 def self.down 7 remove_col umn :users, :fullname 8 end 9 end
ちょっと前まで、add_xxxx_t で yyyyテーブルにxxxxカラムを
追加するという感じの挙動をしていたのですが、それは無くなったみたいですね。
まだRC1なので最終的にどういう形に落ち着くか分かりませんが、
なかなかいい感じです。
今まできちんと動作していなかった、DailyとMonthlyのアーカイブ表示の 実装を修正しました。
記事一覧表示画面の上部に表示されているカレンダーからアクセスできます。
よろしくお願いします。
Railsのroutes.rbでNamed Routeを利用するときに、
メソッド名の競合などで通常は使えない名前をどうしても
利用したい場合、以下のように記述することで利用できます。
config/rou
1 map.send :method_missing, :touch, 'foo/:id/to uch', :action => 'touch'
メソッドがすでに定義されているため、method_mis
が呼ばれなくなっている状態を無理やり回避しています。
Railsのプラグインは、簡単に作れるせいか、おかしな、
というか、随分てきとうな名前のものが多いのですが、最近は
一時期流行していたacts_as_xx系のプラグインに代わり、
xxx_fuという名前のプラグインが増えてきました。
:fields => [ :start_dat etime, :end_datet ime].さて、次に流行するのはどんな名前でしょう。
更新履歴
記事の引越しから漏れていたのでサルベージ。
zsh用のscript/genおよびscript/desの補完関数です。
以下のスクリプトを.zshrcなどに書いておけば、
./script/gに続けてTABキーを押す事で
generatorの入力を補完できます。
~/.zshrc
1 _generate () { 2 if [ ! -f .generators ]; then 3 ./script/g enerate --help | grep '^ [^ ]*: ' | sed 's/[^:]*:/compadd/ ' | sed 's/\,//g' > .generator s 4 fi 5 `cat .generator s` 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
誰かが作らないかなあ、と思って待っていたのですが、 なかなか出て来ないので自分で作りました。 もっと良いものがあったら教えていただけると嬉しいです。