# Map.resources and extensions

**URL:** <https://www.ruby-forum.com/t/map-resources-and-extensions/130660>\
**Category:** Radiant CMS\
**Created:** [March 1, 2008, 2:45pm UTC](https://www.ruby-forum.com/t/map-resources-and-extensions/130660 "2008-03-01T14:45:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [March 1, 2008, 2:45pm UTC](https://www.ruby-forum.com/t/map-resources-and-extensions/130660/1 "2008-03-01T14:45:45Z")

</div>

Hi list,

I am tracking radiant svn and am setting up a new extension following  
the tutorial.

I have the extension loading up and am using scaffold generated by rails  
2.

The problem i am having is that i get a lot of

undefined method `project\_path’ for #ActionView::Base:0x34205ec  
errors.

Not being very good at routing i was hoping someone could help.

in my routes i have

define\_routes do |map|

```
 map.namespace(:admin) do |admin|
    admin.resources :projects
 end

```

end

rake routes shows they are set up correctly, but if i include something  
like (this is stock rails scaffold)

 \<%=h project.name %\> \<%=h project.mailing\_list %\> \<%= link\_to 'Show', project %\> \<%= link\_to 'Edit', edit\_project\_path(project) %\> \<%= link\_to 'Destroy', project, :confirm =\> 'Are you sure?', :method =\> :delete %\>

It gives me the above error.

Anyone have an idea? does map.resources work with extensions or am i  
going to have to wright named routes instead?

Thanks

Mark K.

---

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [March 3, 2008, 2:19am UTC](https://www.ruby-forum.com/t/map-resources-and-extensions/130660/2 "2008-03-03T02:19:26Z")

</div>

Hi Mark,

I’m a newbie too, but I think I might be able to help a bit. In the  
book, “Rails 2: New features for you applications”, Ryan Daigle writes  
about namespaces:

* * *

Namespaces

You can now declare a routing namespace using in a RESTful manner  
with map.namespace. The most common use of this is for establishing  
an administrative section of an application.

map.namespace(:admin) do |admin|  
admin.resources :posts  
end

With this routing definition, you get the standard host of post routes  
and URL helpers, all prefixed with admin:

- admin\_posts – /admin/posts
- admin\_post(post) – /admin/posts/:id
- formatted\_admin\_post(post, format) – /admin/posts/:id.:format
- new\_admin\_post – /admin/posts/new
- edit\_admin\_post(post) – /admin/posts/:id/edit
- etc.

With this namespace, the routing mechanism will try to find a controller  
named Admin::PostsController to satisfy these URLs.

* * *

So, the admin namespace mapping doesn’t generate URL helpers for  
products without including “admin” somewhere.

I think edit\_project\_path(project) should be  
edit\_admin\_project\_path(post).

But like I said, I’m still just getting the hang of Rails so don’t quote  
me on that. Maybe one the more experienced guys here can help further.

Mark K. wrote:

> Hi list,
> 
> I am tracking radiant svn and am setting up a new extension following  
> the tutorial.
> 
> I have the extension loading up and am using scaffold generated by rails  
> 2.
> 
> The problem i am having is that i get a lot of
> 
> undefined method `project\_path’ for #ActionView::Base:0x34205ec  
> errors.
> 
> Not being very good at routing i was hoping someone could help.
> 
> in my routes i have
> 
> define\_routes do |map|
> 
> ```
> map.namespace(:admin) do |admin|
> admin.resources :projects
> end
> 
> ```
> 
> end
> 
> rake routes shows they are set up correctly, but if i include something  
> like (this is stock rails scaffold)
> 
> \<%=h project.name %\> \<%=h project.mailing\_list %\> \<%= link\_to 'Show', project %\> \<%= link\_to 'Edit', edit\_project\_path(project) %\> \<%= link\_to 'Destroy', project, :confirm =\> 'Are you sure?', :method =\> :delete %\>
> 
> It gives me the above error.
> 
> Anyone have an idea? does map.resources work with extensions or am i  
> going to have to wright named routes instead?
> 
> Thanks
> 
> Mark K.

---

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [March 4, 2008, 3:22am UTC](https://www.ruby-forum.com/t/map-resources-and-extensions/130660/3 "2008-03-04T03:22:22Z")

</div>

Hi Mark,

map.resources definitely works in extensions. Here is an example from  
one of my private extensions:

define\_routes do |map|  
map.reorder\_materials ‘/admin/materials/reorder’, :controller =\>  
‘admin/materials’, :action =\> ‘reorder’  
map.resources :materials do |material|  
material.resources :branded\_materials  
end  
map.resources :materials, :path\_prefix =\> ‘/admin’, :name\_prefix  
=\> ‘admin\_’, :controller =\> ‘admin/materials’  
map.home ‘’, :controller =\> ‘materials’, :action =\> ‘index’  
map.admin ‘/admin’, :controller =\> ‘admin/materials’, :action =\>  
‘index’  
end

I’m not completely sure how map.namespace works, having never used it  
myself, but I’d guess you’d need to prefix your url-generation calls  
with “admin\_” having put the resource in the admin namespace. So in  
your case, it should be something like this (untested):

edit\_admin\_project\_path

Good luck!

/Casper F.

---

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [March 3, 2008, 2:22am UTC](https://www.ruby-forum.com/t/map-resources-and-extensions/130660/4 "2008-03-03T02:22:59Z")

</div>

Whoops, I forgot to completely edit that.

I meant to say, “I think edit\_project\_path(project) should be  
edit\_admin\_project\_path(project).”

Also, the book is “Rails 2: New features for your applications”. I  
forgot the ‘r’ on “your” in my previous post.

Ben M. wrote:

> Hi Mark,
> 
> I’m a newbie too, but I think I might be able to help a bit. In the  
> book, “Rails 2: New features for you applications”, Ryan Daigle writes  
> about namespaces:
> 
> * * *
> 
> Namespaces
> 
> You can now declare a routing namespace using in a RESTful manner  
> with map.namespace. The most common use of this is for establishing  
> an administrative section of an application.
> 
> map.namespace(:admin) do |admin|  
> admin.resources :posts  
> end
> 
> With this routing definition, you get the standard host of post routes  
> and URL helpers, all prefixed with admin:
> 
> - admin\_posts – /admin/posts
> - admin\_post(post) – /admin/posts/:id
> - formatted\_admin\_post(post, format) – /admin/posts/:id.:format
> - new\_admin\_post – /admin/posts/new
> - edit\_admin\_post(post) – /admin/posts/:id/edit
> - etc.
> 
> With this namespace, the routing mechanism will try to find a controller  
> named Admin::PostsController to satisfy these URLs.
> 
> * * *
> 
> So, the admin namespace mapping doesn’t generate URL helpers for  
> products without including “admin” somewhere.
> 
> I think edit\_project\_path(project) should be  
> edit\_admin\_project\_path(post).
> 
> But like I said, I’m still just getting the hang of Rails so don’t quote  
> me on that. Maybe one the more experienced guys here can help further.

---

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [March 7, 2008, 9:27am UTC](https://www.ruby-forum.com/t/map-resources-and-extensions/130660/5 "2008-03-07T09:27:30Z")

</div>

On 3 Mar 2008, at 09:19, Casper F. wrote:

> end  
> map.resources :materials, :path\_prefix =\> ‘/admin’, :name\_prefix  
> =\> ‘admin\_’, :controller =\> ‘admin/materials’  
> map.home ‘’, :controller =\> ‘materials’, :action =\> ‘index’  
> map.admin ‘/admin’, :controller =\> ‘admin/materials’, :action =\>  
> ‘index’  
> end

Thanks,

adding map.resources :projects, :path\_prefix =\> ‘/admin’, :controller  
=\> ‘admin/projects’ seems to have done the trick.

Mark
