[Radiant] map.resources and extensions

Casper Fabricius me at casperfabricius.com
Mon Mar 3 03:19:11 CST 2008


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 Fabricius


On 03/03/2008, at 9:22, Mark Kirby wrote:

> [sorry if this comes through twice]
>
> 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)
>
> <tr>
>     <td><%=h project.name %></td>
>     <td><%=h project.mailing_list %></td>
>     <td><%= link_to 'Show', project %></td>  ** This line trips the  
> error **
>     <td><%= link_to 'Edit', edit_project_path(project) %></td>
>     <td><%= link_to 'Destroy', project, :confirm => 'Are you  
> sure?', :method => :delete %></td>
> </tr>
>
> It gives me the above error.
>
> if i also add map.resources :projects the links work but so do the  
> non admin prefixed links.
>
> Anyone have an idea? does map.resources work with extensions or am i  
> going to have to wright named routes instead?
>
> Will the wiki be updated to reflect the lack of automatic scaffold  
> in rails now?
>
> Thanks
>
> Mark Kirby
>
> _______________________________________________
> Radiant mailing list
> Post:   Radiant at radiantcms.org
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant



More information about the Radiant mailing list