Bug in routes?

Hi,

Is this a bug in routes, or something I’m doing wrong. Basically from
what
I can tell the url_for being generated in the case where my existing
controller had a forward slash (i.e. active_rbac/login) may be causing a
problem. I’m creating a link to a different controller however the URL
created has a piece of the previous controller in it (i.e.
active_rbac/). I
put a breakpoint in the view and the run the following to confirm, see
below. Also note the login aspects use a plugin.

Is this a bug?

============== debug / irb =========================
irb(#<#Class:0x39bea80:0x39bea50>):051:0* params
=> {“action”=>“login”, “controller”=>“active_rbac/login”,
“locale”=>“en”}

irb(#<#Class:0x39bea80:0x39bea50>):052:0> session[:locale]
=> “en”

irb(#<#Class:0x39bea80:0x39bea50>):053:0> url_for
=> “/en/active_rbac/login/login”

irb(#<#Class:0x39bea80:0x39bea50>):054:0> url_for :locale => “fr”
=> “/fr/active_rbac/login”

irb(#<#Class:0x39bea80:0x39bea50>):055:0> url_for :locale => “fr”,
:controller => “splash”
=> “/fr/active_rbac/splash” <== PROBLEM HERE, I expect to see
“/fr/splash”

irb(#<#Class:0x39bea80:0x39bea50>):056:0>

====================
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/:en', :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.splash ':locale', :controller => 'splash', :locale => nil, 

:defaults
=> { :locale => “en” }
map.connect ‘:locale/:controller/:action/:id’,
:defaults => { :locale => “en”, :controller => “splash” }

end

Hi,

I’m still battling this one and am yet unsure whether this is a bug or
not.
It would be great if someone could put me out of my misery and confirm
whether this is bug or not?

With the latest testing to characterise the problem it seems to be
something
to do with (a) controllers a sub-directory down &/or (b) url_for usage
in a
layout perhaps. That is in the sense that I have a “url_for” which
resolves
fine when the context is one controller but throws an error when in the
context of another.

Key points include:

  1. routes.rb routes a URL to a controller which is down 1
    subdirectory
  • Example
    map.connect ‘:locale/mygoodness’, :controller =>
    ‘highlevel/midlevel’,
    :action => ‘testaction’, :defaults => {:locale => nil}
    map.connect ‘:locale/contactbackdoor’, :controller => “contacts”,
    :defaults => {:locale => nil}
  1. controller picks this up ok
    class Highlevel::MidlevelController < ApplicationController
    def testaction
    puts “Highlevel::MidlevelController - testaction”
    end
    end

  2. the “views/highlevel/midlevel/testaction.rhtml” view is small as
    the application.rb has a layout “site_layout” line.

  3. The “site_layout” has
    <%= link_to "2-contacts ", :controller => ‘contacts’ %>

  4. The site_layout link is generator OK when it is used from the
    opening page, BUT when it is utilised after a URL has come in via the
    controller which is down a sub-directory ( i.e. 'highlevel/midlevel)
    an error is encountered. See below.

    1. Note the hash indicated in the error below has “:controller=>”
      highlevel/contacts" and it has seemed to munge the
      “highlevel/midlevel” controller name with the “contacts”
      controller name.
    2. Interestingly if I change the “url_for” line in the layout
      to:
    • <%= link_to "2-contacts ", :controller => nil %> one sees the
      following in the error
      :controller=>"highlevel/highlevel/midlevel
      "

      • <%= link_to "2-contacts ", :controller => “” %> one sees
        the following in the error
        :controller=>“highlevel/”

===============================================
ActionController::RoutingError in Highlevel/midlevel#testaction

Showing app/views/layouts/site_layout.rhtml where line #15 raised:

No url can be generated for the hash {:action=>“index”,
:controller=>“highlevel/contacts”}

Extracted source (around line #15):

12:
13:

<%= link_to "1 " %>


14:
15:

<%= link_to "2-contacts ", :controller => ‘contacts’ %>

16: 17:

<%#= link_to "Plugin Login", {:controller => '/rbac/login', :action => 'login'} %>

18:

RAILS_ROOT: ./script/…/config/…
Application Trace http://localhost:3001/en/mygoodness# | Framework
Tracehttp://localhost:3001/en/mygoodness#| Full
Trace http://localhost:3001/en/mygoodness#

generated_code/routing/generation.rb:65:in generate_default_path' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/routing.rb:473:ingenerate_path’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/routing.rb:469:in
generate' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/url_rewriter.rb:44:inrewrite_path’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/url_rewriter.rb:11:in
rewrite' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:488:inurl_for’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/url_helper.rb:27:in
url_for' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/url_helper.rb:59:inlink_to’
#{RAILS_ROOT}/app/views/layouts/site_layout.rhtml:15:in
`_run_rhtml_layouts_site_layout’
-e:4

generated_code/routing/generation.rb:65:in generate_default_path' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/routing.rb:473:ingenerate_path’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/routing.rb:469:in
generate' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/url_rewriter.rb:44:inrewrite_path’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/url_rewriter.rb:11:in
rewrite' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:488:inurl_for’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/url_helper.rb:27:in
url_for' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/url_helper.rb:59:inlink_to’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:316:in
compile_and_render_template' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:292:inrender_template’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:251:in
render_file' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/layout.rb:251:inrender_without_benchmark’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in
render' C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:inmeasure’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in
render' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:942:inperform_action_without_filters’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in
perform_action_without_benchmark' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:inperform_action_without_rescue’
C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in measure' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:inperform_action_without_rescue’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in
perform_action' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:inprocess_without_filters’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in
process_without_session_management_support' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:inprocess’
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:inhandle_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:inservice’
C:/InstantRails/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run' C:/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:173:instart_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:instart’
C:/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:92:in start' C:/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:23:instart’
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:indispatch’
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:inrequire’
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:inrequire’
script/server:3

generated_code/routing/generation.rb:65:in generate_default_path' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/routing.rb:473:ingenerate_path’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-
1.12.5/lib/action_controller/routing.rb:469:in generate' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/url_rewriter.rb:44:inrewrite_path’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-
1.12.5/lib/action_controller/url_rewriter.rb:11:in rewrite' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:488:inurl_for’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-
1.12.5/lib/action_view/helpers/url_helper.rb:27:in url_for' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/url_helper.rb:59:inlink_to’
#{RAILS_ROOT}/app/views/layouts/site_layout.rhtml:15:in
`_run_rhtml_layouts_site_layout’

C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:316:in
compile_and_render_template' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:292:inrender_template’

C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:251:in
render_file' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/layout.rb:251:inrender_without_benchmark’

C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in
render' C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:inmeasure’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-
1.12.5/lib/action_controller/benchmarking.rb:53:in render' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:942:inperform_action_without_filters’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-
1.12.5/lib/action_controller/filters.rb:368:in
perform_action_without_benchmark' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:inperform_action_without_rescue’

C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in measure' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:inperform_action_without_rescue’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-
1.12.5/lib/action_controller/rescue.rb:82:in perform_action' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:inprocess_without_filters’
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-
1.12.5/lib/action_controller/filters.rb:377:in
process_without_session_management_support' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:inprocess’

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:inhandle_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:inservice’
C:/InstantRails/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run' C:/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:173:instart_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:instart’
C:/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:92:in start' C:/InstantRails/ruby/lib/ruby/1.8/webrick/server.rb:23:instart’

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:indispatch’
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:inrequire’

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:inrequire’
script/server:3

-e:4

Request

Parameters: {“locale”=>“en”}

Show session dump http://localhost:3001/en/mygoodness#


flash: !map:ActionController::Flash::FlashHash {}

Response Headers: {“Status”=>“200 OK”, “cookie”=>[],
“Cache-Control”=>“no-cache”}

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs