3 日坊主日記
2005-02-27 [長年日記]
_ [Rails] session_id を Cookie ではなく query parameter として渡す(4)
Routes だと簡単に書けた。
- config/routes.rb:
map.connect ':session_id/:controller/:action/:id', :requirements => {:session_id => /[a-f0-9]{32}/}
# Install the default route as the lowest priority.
map.connect ':controller/:action/:id'
dispatch{.rb,.cgi} は以前と同じ。
追記: 同じじゃなかった。controller_prefix を key にしないと取れない。
cgi = CGI.new session_id = cgi.query_string ? CGIMethods.parse_query_parameters(cgi.query_string)["controller_prefix"] : nil Dispatcher.dispatch cgi, :session_id => session_id
script/server でも Routes は有効なので、lib/webrick_server.rb はそのままでいい。
_ [Rails] has_and_belongs_to_many な find
Person n..n Group と思いねえ。 ある Group (複数可) に所属する Person を得るにはどうするか。
# @manabe -> Person
# @tencho -> Group
assert_equal([@manabe.name], Person.find_all_by_groups([@tencho]).map {|person| person.name }) # だめ
#=> NoMethodError: undefined method `find_all_by_groups' for Person:Class
むう。
assert_equal([@manabe.name], ActiveRecord::Base.connection.select_all("select distinct person_id from groups_people where group_id in \
(#{ [@tencho].map {|group| group.id }.join(',') })").map {|row| Person.find(row["person_id"]).name })
まあ SQL レベルに降りるのは嫌いじゃないが、書けても良さそうではある。
追記: distinct がないと重複してしまう。
携帯でログインできないという報告。
昔のハック
がうまく動作しなくなっていました。(T_T)
http://svn.rails2u.com/public/plugins/trunk/active_heart/lib/trans_sid.rb
を使うことにしました。
ha-rd-po-rn-fu-ck 4760964 News about renault gordini.
ha-rd-po-rn-fu-ck 4760964 Variants of kia used car.
ha-rd-po-rn-fu-ck 4760964 Of 2005 toyota rav4 review and more
ha-rd-po-rn-fu-ck 4760964 brush guard h3 hummer friends
ha-rd-po-rn-fu-ck 4760964 Eye of toyota tercel carburetor
ha-rd-po-rn-fu-ck 4760964 Fresh information about ford e series van.
ha-rd-po-rn-fu-ck 4760964 Aggregator of ford stock market sites
ha-rd-po-rn-fu-ck 4760964 Catalogue of 2007 250 lexus.
ha-rd-po-rn-fu-ck 4760964 Description of electronic car compass.
amazon.comからRuby on Rails が届いて、Ruby on Railsを初めて2日目です。本にSessionIDはCookieのみですと書いてあり、がーんとショックでした。<br>携帯も相手にするからです。そうしたら、このページを見つけました。<br>何とかなるんですね。よかったです。勉強続けます。