Forum: Ruby on Rails Controllers in modules, not recognised - driving me mad!

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1e99128ebac5ca41c91940291d315332?d=identicon&s=25 Luke Redpath (lukeredpath)
on 2006-03-27 01:34
Hi, I hope somebody can help me here but I'm having a very strange
problem getting Rails to recognise controllers inside modules. The
strange thing is, it was working the other day and I've not changed
anything as far as I'm aware. I'm running on OSX using Ruby 1.8.4 and
Rails RC1 (but I've also tried rolling back to Rails 1.0 and tried Edge
Rails) and the problem occurs using lighty, webrick and when I run my
functional tests (I have a few assert_routings).

I have a Dashboard controller in an admin module. I have the following
file:

app/controllers/admin/dashboard_controller.rb
---
class Admin::DashboardController < ActionController::Base
  def index
    # do stuff
  end
end

Now, this should be automatically picked up by Rails as
http://myapp/admin/dashboard and http://myapp/admin/dashboard/index -
but they aren't, I get routing errors.

I also have the following test:

require File.dirname(__FILE__) + '/../test_helper'

class RoutingTest < Test::Unit::TestCase
  def setup
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
  end

  def test_admin_routing
     assert_routing '/admin', :controller => 'admin/dashboard', :action
=> 'index'
     assert_routing '/admin/dashboard', :controller =>
'admin/dashboard', :action => 'index'
  end
end

These tests fail.

What could be happening here? There isn't anything revealing in my logs,
and like I said this was working the other day - they only work I've
been doing on my app since then is on one of my model classes and its
unit tests - I've not been touching my views/controllers.

Here's the relevant exerpt from my logs:

Processing Base#index (for 127.0.0.1 at 2006-03-27 00:34:05) [GET]
  Session ID: 6145b5c6d7884639db0adc70113f5e86
  Parameters: {}

ActionController::RoutingError (Recognition failed for
"/admin/dashboard/"):
    .//vendor/rails/actionpack/lib/action_controller/routing.rb:488:in
`recognition_failed'
    .//vendor/rails/actionpack/lib/action_controller/routing.rb:478:in
`recognize!'
    .//vendor/rails/railties/lib/dispatcher.rb:38:in `dispatch'
    .//vendor/rails/railties/lib/webrick_server.rb:115:in
`handle_dispatch'
    .//vendor/rails/railties/lib/webrick_server.rb:81:in `service'
    /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    /usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    /usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start'
    /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `start'
    /usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start'
    /usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start'
    .//vendor/rails/railties/lib/webrick_server.rb:67:in `dispatch'
    .//vendor/rails/railties/lib/commands/servers/webrick.rb:59
    .//vendor/rails/activesupport/lib/active_support/dependencies.rb:149:in
`require'
    .//vendor/rails/railties/lib/commands/server.rb:30
    script/server:3


Rendering
./script/../config/../vendor/rails/actionpack/lib/action_controller/templates/rescues/layout.rhtml
(404 Page Not Found)
1e99128ebac5ca41c91940291d315332?d=identicon&s=25 Luke Redpath (lukeredpath)
on 2006-03-27 02:55
OK I finally worked this out after much hairpulling! The aforementioned
model I had been working on was called Admin and this was conflicting
with the 'admin' module.
E24b2a1d71b7365186a934a09ee6f7c3?d=identicon&s=25 Carl-Johan Kihlbom (Guest)
on 2006-03-28 00:42
(Received via mailing list)
Thank you for this! I've also been pulling my hair, but no more! Thanks!
This topic is locked and can not be replied to.