On 6 May 2009, at 17:30, James Bebbington wrote:
<snip>
Is anyone aware of a non-hacky way to rename the radiant admin route
(i.e. not just cloning and tweaking the gem's routes) to avoid this
clash?
So I've spent a little time looking into this, in case anyone is
interested this is what I've found out so far:
* It appears that radiant doesn't provide a way of configuring the
path_prefix used by the admin area (fair enough really, you can't
predict all use cases)
* Extensions can and generally do generate their own routes within
the admin namespace (not a ground-breaking discovery)
With the above in mind I figured it might be possible to create an
extension which when loaded after all others, re-writes all pre-
existing admin related routes. So far I've hacked together the
following which when placed at the very end of your_radiant_app/config/
environment.rb half does the job:
old_path_prefix, new_path_prefix = 'admin', 'cms'
ActionController::Base.logger.debug "** Rewriting /#{old_path_prefix}
routes to /#{new_path_prefix}"
ActionController::Routing::Routes.routes.each do |route|
if route.segments[1] && route.segments[1].respond_to?(:value) &&
route.segments[1].value == old_path_prefix
route.segments[1].value = new_path_prefix
end
end
The above seems to work when it comes to route recognition, i.e. a
request to /cms/pages routes to Admin::PagesController#index.
Unfortunately the URLs generated in the view are still locked to the
old path_prefix i.e. /admin/pages. Strangely though, on the console
named routes do seem to work as I'd hoped:
$ ./script/console
Loading development environment (Rails 2.1.2)
>> include ActionController::UrlWriter
=> Object
>> ActionController::UrlWriter.admin_pages_path
=> "/cms/pages"
There is also a further problem with all of this in that it appears
that named routes aren't always used; there are a number of places
within both radiant and extensions that are using simple string
interpolation to generate URLs. The most problematic being the
extension generator template which appears to promote the non-use of
named routes:
# admin.tabs.add "<%= extension_name %>", "/admin/<%= file_name
%>", :after => "Layouts", :visibility => [:all]
Some response body regex hackery could deal with this I guess but that
just feels a bit dirty and slow. I think at this stage the simplest
solution for my situation is to go find another host. Any
recommendations for cheap, UK based, shared hosts gratefully received.
Cheers,
James.
_______________________________________________
Radiant mailing list
Post: Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site: http://lists.radiantcms.org/mailman/listinfo/radiant