# Noob help with routing

**URL:** <https://www.ruby-forum.com/t/noob-help-with-routing/130736>\
**Category:** Engines Development\
**Created:** [March 2, 2008, 10:02pm UTC](https://www.ruby-forum.com/t/noob-help-with-routing/130736 "2008-03-02T22:02:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [March 2, 2008, 10:02pm UTC](https://www.ruby-forum.com/t/noob-help-with-routing/130736/1 "2008-03-02T22:02:19Z")

</div>

Hi all,  
I am trying to create my own plugin, and I’m not having much luck. I  
have  
my structure set up with my controller, models and views. I’ve been  
able to  
successfully migrate my database, however I can’t get my routes to work.  
I  
have the following basic directory structure

plugins  
± project\_ranking  
±controllers  
| ±project\_rank\_controller.rb  
+models  
| ±project\_rank.rb  
+views  
| ±order.rhtml  
+routes.rb

I’m trying to create a new route, and here is what I’ve defined in my  
routes.rb file.

ActionController::Routing::Routes.draw do |map|

connect ‘projects/order’, :controller =\> ‘project\_rank`’, :action =\>  
‘order’

end

Here is what I’ve added to the base project’s routes.rb

map.home ‘’, :controller =\> ‘welcome’

#my new routing  
map.from\_plugin :project\_ranking

### Other routes

However, when I try to load the default projects page (not a plugin). I  
receive the following routing errors

“no route found to match “/” with {:method=\>:get}”

If I comment out my map.from\_plugin, everything works fine again.

Any advice/help would be great.

Thanks,  
Todd

---

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [March 3, 2008, 1:08am UTC](https://www.ruby-forum.com/t/noob-help-with-routing/130736/2 "2008-03-03T01:08:17Z")

</div>

The routes.rb file in your plugin should only contain the inner  
section of a normal application routes.rb file, I.e.

connect ‘/path/:parameters’, :controller =\> ‘plugin\_controller’

Note that it doesn’t even contain the ‘map’.

HTH

James

---

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [March 3, 2008, 4:55am UTC](https://www.ruby-forum.com/t/noob-help-with-routing/130736/3 "2008-03-03T04:55:22Z")

</div>

Thanks James! That fixed part of my problem. I’m successfully getting  
my  
routes to work now. However, it seems that my controller is never  
called,  
and I’m now receiving a 404 error instead of the apps layout with  
“hello!”  
in the body as I expected. The application I’m creating a plugin for is  
redmine. It uses site layouts and the standard “\<%= yield %\>” code for  
the  
body that is rendered from the called controller/action/view. I simply  
have  
the following in my controller,and view, am I missing something else? I  
set  
the order action to be called when the projects/order url is called.

routes.rb

connect ‘projects/order’, :controller =\> ‘project\_rank’, :action =\>  
‘order’

project\_rank\_controller.rb

class ProjectRankController \< ProjectsController  
def order  
print ‘foobar’;  
end  
end

order.rhtml

hello!

Thanks,  
Todd

---

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [March 8, 2008, 7:21pm UTC](https://www.ruby-forum.com/t/noob-help-with-routing/130736/4 "2008-03-08T19:21:24Z")

</div>

I think you could extend ProjectsController - but it would mean that  
your ProjectRankController _is a_ ProjectsController. So, for example,  
I am not sure it would automatically know about your project\_rank  
model - it might just know about the project model.

Quoting Todd N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [March 5, 2008, 5:10am UTC](https://www.ruby-forum.com/t/noob-help-with-routing/130736/5 "2008-03-05T05:10:30Z")

</div>

Well, just a follow up. I fixed my issue by extending  
“ApplicationController”. When I extend “ProjectsController” which is  
part  
of the base app, everything blows up. Are we not allowed to extend code  
from the base app in rails engine?

Todd

---

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [March 9, 2008, 9:41pm UTC](https://www.ruby-forum.com/t/noob-help-with-routing/130736/6 "2008-03-09T21:41:23Z")

</div>

Hi Cynthia,  
I tried changing my controller to the following.

require\_dependency “projects\_controller”

class ProjectRankController \< ProjectsController  
layout ‘base’  
#require a manager to update priorities  
before\_filter :require\_manager, :only =\> :update  
before\_filter :authorize, :except =\> :order

…

end

However when I try my overridden “list” action, it doesn’t work with the  
projects controller routes. The default is “projects/list”, but my list  
action never gets called. If my Project Rank Controller is a Project  
controller, do I still have to change the routes to call my subclass?

Thanks,  
Todd
