[前][次][番号順一覧][スレッド一覧]

rails:3377

From: ohsawa sumiki <sumikio@g...>
Date: Mon, 1 Feb 2010 22:29:01 -0800
Subject: [rails:3377] ピリオドを含むparams[:id]について

大澤と申します。
数時間調べているのですが、行き詰ってしまいました。
テスト用のコードもGITHUBにあげておきました、
どなたか力を貸していただければと思い、メールしています。

■やりたいこと
1./users/:id/activate という型のURL
2.:idには、ピリオドを含む可能性がある。

■現在のconfig/routesファイル
--------------------------------------------------------
  map.resources :users, :member => { :activate => :any },
:requirements => { :id => /.*/}
--------------------------------------------------------

■現在の動作
/users/a/edit              #OK
/users/a/activate        #OK
/users/a.aa/edit         #OK
/users/a.aa/activate   #NG

map.resourcesにmemberで追加したメソッドを、params[:id]にピリオドを含むデータをリクエストした場合、
Routing Errorが発生する。(showメソッドがある場合はshowが呼ばれ、params[:id]に以降が入る。)
No route matches "/users/a.aa/activate" with {:method=>:get}
(ログは一番下につけておきます)

ぐぐって見たところ、:requirements => { :id => /.*/}でうまくいった人をみつけたのですが、うまくいかず、
:requirements => { :id => %r([^/;,?]+) } というのも見つけたのですが、
これでも、だめでした。

どうも、:requirements => { :id => /.*/}を設定すると、a.aa/activateの部分すべてがparams[id]に設定されて
いるようで、自分で正規表現を書いてみたのですが、結局うまくいきませんでした。(あまり自信なし)
{ :id => /[a-zA-Z0-9.]*/}


■環境は
ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

rails -v
Rails 2.2.2

Windows XP SP3

■テストコード
以下に公開しています。
git clone git@g...:sumiki/route_test.git

*カリフォルア時間で活動しているので、返信が遅れる場合があります。


エラーログ
---------------------------------------------------

ActionController::RoutingError (No route matches
"/users/a.aa/activate" with {:method=>:get}):
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/routing/recognition_optimisation.rb:66:in
`recognize_path'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/routing/route_set.rb:386:in
`recognize'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:182:in
`handle_request'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:110:in
`dispatch_unlocked'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:123:in
`dispatch'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:122:in
`synchronize'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:122:in
`dispatch'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:132:in
`dispatch_cgi'
    C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:39:in
`dispatch'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/../lib/mongrel/rails.rb:76:in
`process'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/../lib/mongrel/rails.rb:74:in
`synchronize'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/../lib/mongrel/rails.rb:74:in
`process'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:159:in
`process_client'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in
`each'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in
`process_client'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`run'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`initialize'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`new'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`run'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in
`initialize'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in
`new'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in
`run'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:282:in
`run'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:281:in
`each'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:281:in
`run'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:128:in
`run'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/command.rb:212:in
`run'
    C:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:281
    C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in
`load_without_new_constant_marking'
    C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in
`load'
    C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in
`new_constants_in'
    C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in
`load'
    C:/ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/commands/servers/mongrel.rb:64
    C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
    C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in
`require'
    C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in
`new_constants_in'
    C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in
`require'
    C:/ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/commands/server.rb:49
    C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
    C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    script/server:3

--
ML: rails@r...
使い方: http://QuickML.com/

[前][次][番号順一覧][スレッド一覧]

->    3377 2010-02-02 07:29 [sumikio@g...        ] ピリオドを含むparams[:id]について       
      3378 2010-02-02 08:19 ┣[sugi@n...           ]                                       
      3379 2010-02-02 08:32 ┗[zn@m...             ]                                       
      3380 2010-02-02 16:38  ┗[sumikio@g...        ]                                     
      3381 2010-02-03 01:40   ┗[sumikio@g...        ]