I’m creating a restful (for the most part) website that is read-only
from a user perspective, but has an admin section where content is
generated. I would like to do something like the following for this
admin portion:
http://www.mysite.com/admin/[controller]
I’ve ran into several stumbling blocks and after 2 days, have not found
a solution. I started by creating a namespace.
map.namespace(:admin) do |admin|
admin.resources :categories
admin.resources :sections
admin.resources :items
end
I then used these commands to generate the right resources:
script/generate resource admin/category title:string
script/generate resource admin/section title:string category:references
script/generate resource admin/item title:string, section:references
Using this approach, I had controllers, models, and views created in an
‘admin’ directory within each appropriate folder. Few questions so
far…
(1) Having namespaced models seems like a bad practice. Yet, when I
reconfigure them to not be namespaced, other resource routing fails such
as creating a link like:
<% for category in @categories %>
<%= link_to “show category” category %>
<% end %>
(2) When trying to run functional tests on controllers within the
‘admin’ namespace, I get all kinds of errors. Since the fixtures are in
‘admin/’ within the ‘test’ directory, Rails doesn’t know to
look there. I’ve found no way to configure that and moving it outside
the ‘admin’ only makes the problem worse. So despite my user interface
working, I cannot write any tests to validate it in this configuration.
I could really use some help, this issue is now breaching about 2 days
of effort with no results. Has anyone had similar problems or can anyone
offer some potential strategies to make this work?
I really appreciate anyons help. Thanks in advance.