Map.resources and extensions

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.

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.

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.

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.

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