question re routes.rb, and issue with redirected URL coming back with double entries???

Hi,

I seem to be getting a routing error due to a before filter I have puut in application.rb that assists with localization. The before_filter is checking the locale and in this case is performing a redirect. The parameters look ok just as the redirect request is set off in the before_filter, BUT THEN the URL that comes back from the client is WRONG with double entries (
e.g. “/active_rbac/active_rbac/login/login”)

Any advice on how to fault find this?

Could this be the way rails determines what the URL should be for a request. Does it back-calculate from routes.rb
information? Perhaps I’ve got inconsistent data in my routes.rb file (e.g. more than one map with same number of parameters). I’ll copy my routes.rb below.

Tks
Greg

=============== HTML BROWSER ERROR ===============================================

Routing Error
Recognition failed for “/active_rbac/active_rbac/login/login”

========= APPLICATION.RB, before_filter ===========================================
before_filter :set_locale
def set_locale

puts "application.rb: params[:locale]=#{params[:locale]}"
default_locale = 'en'
@locale = params[:locale] || session[:locale] || default_locale
session[:locale] = @locale
begin

  Localization.lang = @locale
  puts "application.rb - set locale to #{@locale}"
  redirect_to params.merge( 'locale' => Localization.lang ) and return false if params[:locale].nil?   <== REDIRECTS HERE

rescue
  Localization.lang = default_locale
  redirect_to params.merge( 'locale' => Localization.lang ) and return false
end

end

=============CONSOLE - puts ==============================================================

application.rb - params = actionlogincontrolleractive_rbac/login
application.rb - set locale to en
- params merged = actionlogincontrolleractive_rbac/loginlocaleen
- urlfor =
127.0.0.1
- - [17/Sep/2006:10:20:57 E. Australia Standard Time] “GET /login HTTP/1.1” 302 133
http://localhost:3000/?locale=en -> /login
127.0.0.1
- - [17/Sep/2006:10:20:58 E. Australia Standard Time] “GET /active_rbac/active_rbac/login/login?locale=en HTTP/1.1” 404 624
http://localhost:3000/?locale=en
-> /active_rbac/active_rbac/login/login?locale=en

=============LOG FILE=======================================
Processing LoginController#login (for 127.0.0.1 at 2006-09-17 10:20:58) [GET]

Session ID: c04aec03211733ac75632f0834b14a53
Parameters: {“action”=>“login”, “controller”=>“active_rbac/login”}
Redirected to
http://localhost:3000/active_rbac/active_rbac/login/login?locale=en

Filter chain halted as [set_locale] returned false
Completed in 0.00010 (10000 reqs/sec) | DB: 0.00000 (0%) | 302 Found [
http://localhost/login
]
ActiveRbac::ComponentController: missing default helper path active_rbac/component_helper
ActiveRbac::LoginController: missing default helper path active_rbac/login_helper

Processing Base#index (for 127.0.0.1 at 2006-09-17 10:20:58) [GET]
Session ID: c04aec03211733ac75632f0834b14a53
Parameters: {“locale”=>“en”}

ActionController::RoutingError (Recognition failed for “/active_rbac/active_rbac/login/login”):

C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/routing.rb:522:in `recognition_failed'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/routing.rb:512:in `recognize!'

C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in `dispatch'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:115:in `handle_dispatch'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-

1.1.6/lib/webrick_server.rb:81:in service' C:/InstantRails/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in service’
C:/InstantRails/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run' C:/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:173:in start_thread’

C:/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
C:/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'
C:/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'

C:/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'
C:/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:67:in `dispatch'

C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/servers/webrick.rb:59
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-

1.3.1/lib/active_support/dependencies.rb:147:in require' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/server.rb:30 C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in require’

C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'
./script/server:3
-e:4

Rendering C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-
1.12.5/lib/action_controller/templates/rescues/layout.rhtml (404 Page Not Found)

=====================routes.rb=================================
ActionController::Routing::Routes.draw do |map|
map.connect
‘/admin/group/:action/:id’,
:controller => ‘active_rbac/group’
map.connect ‘/admin/role/:action/:id’,
:controller => ‘active_rbac/role’
map.connect ‘/admin/static_permission/:action/:id’,

    :controller => 'active_rbac/static_permission'
map.connect '/admin/user/:action/:id',
    :controller => 'active_rbac/user'

map.connect '/login', :controller => 'active_rbac/login',

    :action => 'login'
map.connect '/logout', :controller => 'active_rbac/login',
    :action => 'logout'
map.connect '/register/confirm/:user/:token',
    :controller => 'active_rbac/registration',

    :action => 'confirm'
map.connect '/register/:action/:id',
    :controller => 'active_rbac/registration'


map.connect '', :controller => "splash"
 map.connect

‘:controller/:action/:sort/:order’
map.connect ‘:locale/:controller/:action/:permalink’
map.connect ‘:controller/:action/:id’

end

PS. ummm…can ones routes.rb
can contain more than one mapping with the same number of parameters or
not? i.e. if it did how would rails know how to back calculate a url_for or a redirect_to request? Wonder if this would explain my problem? I have the following lines in my routes.rb that both have 4 parameters:

map.connect
‘:controller/:action/:sort/:order’

map.connect ‘:locale/:controller/:action/:permalink’

Can anyone provide an overview of the business logic behind the “url_for” functionality in relation to how it works given there may be many routes specified in ones “routes.rb” file? How does it determine which mapping to use & rules behind populating the URL?

I stated to look at the rails code around started getting a headache :frowning: (still not quite up to this level in ruby/rails)