SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Sep 2000
    Location
    England
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Controller modules routing error

    I'm having real trouble with controller modules - they just don't seem to be getting picked up by Rails.

    I've created two controllers via scaffold - Forum::ForumsController and Forum::TopicsController and neither works.

    When I load /forum/forums in the browser, I get a routing error:

    Recongnition failed for "/forum/forums"
    The controllers are both where they should be in app/forum with correct file and class names.

    Does anything else need to be done to get these working?

    Thanks,
    Adam

  2. #2
    SitePoint Enthusiast Stevenwulf's Avatar
    Join Date
    May 2002
    Location
    Berkeley
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To diagnose this I would need to see your routes.rb file. Could you post the contents of this file?

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2000
    Location
    England
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    routes.rb
    Code:
    ActionController::Routing::Routes.draw do |map|
      # The priority is based upon order of creation: first created -> highest priority.
      
      # Sample of regular route:
      # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
      # Keep in mind you can assign values other than :controller and :action
    
      # Sample of named route:
      # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
      # This route can be invoked with purchase_url(:id => product.id)
    
      # You can have the root of your site routed by hooking up '' 
      # -- just remember to delete public/index.html.
      # map.connect '', :controller => "welcome"
    
      # Allow downloading Web Service WSDL as a file with an extension
      # instead of a file named 'wsdl'
      map.connect ':controller/service.wsdl', :action => 'wsdl'
    
      # Install the default route as the lowest priority.
      map.connect ':controller/:action/:id'
      
      map.connect '', :controller => 'news'
    end
    Only the last line added to default.

  4. #4
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may have made a mistake in your original post but the two controller files should be app/controllers/forum/forums_controller.rb and app/controllers/forum/topics_controller.rb. I don't use the generate controller script often - check its generated the controller classes like this:

    Code:
    class Forum::ForumsController < ApplicationController
    end
    
    class Forum::TopicsController < ApplicationController
    end
    You shouldn't need to modify your routes, this should work out of the box.

  5. #5
    SitePoint Enthusiast Stevenwulf's Avatar
    Join Date
    May 2002
    Location
    Berkeley
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @luke
    "this should work out of the box"

    really?

    For my routes, when using controllers within modules I have:
    Code:
     map.connect 'module_name/',
     	:controller => 'module_name/controller_name',
     	:action => 'action_name'
    Of course I may be creating more work for myself than neccessary. Anyway, that's how I do it.

    In adamp's case I would do:

    Code:
     map.connect 'forum/',
      	:controller => 'forum/topics',
      	:action => 'index'

  6. #6
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, it definately works out of the box. You would need to add a route for every controller within your module otherwise.

  7. #7
    SitePoint Zealot
    Join Date
    Sep 2000
    Location
    England
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I did miss a bit out - they are indeed app/controllers/forum/forums_controller.rb and app/controllers/forum/topics_controller.rb and with the Forum::ForumsController and Forum::TopicsController class names.

    I think I'll try removing them and re-creating by hand tomorrow and also try the specific routes.rb code just to try and see where its going wrong.

    Thanks for the advice.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •