mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
This patch allows urls to be of the form :module/:controller/:action as well as :controller/:action/:id where :id is no entirely numeric by determining if what would be :module corresponds to a directory in app/controllers. If it does not then the :controller/:action/:id scheme is used.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@150 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
605bc77533
commit
e5a8d8ebbb
1 changed files with 10 additions and 1 deletions
|
@ -136,11 +136,20 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet
|
||||||
when %r{^/#{component}/#{component}/$} then
|
when %r{^/#{component}/#{component}/$} then
|
||||||
{ :module => $1, :controller => $2, :action => "index" }
|
{ :module => $1, :controller => $2, :action => "index" }
|
||||||
when %r{^/#{component}/#{component}/#{component}$} then
|
when %r{^/#{component}/#{component}/#{component}$} then
|
||||||
|
if DispatchServlet.modules(component).include?($1)
|
||||||
{ :module => $1, :controller => $2, :action => $3 }
|
{ :module => $1, :controller => $2, :action => $3 }
|
||||||
|
else
|
||||||
|
{ :controller => $1, :action => $2, :id => $3 }
|
||||||
|
end
|
||||||
when %r{^/#{component}/#{component}/#{component}/#{id}$} then
|
when %r{^/#{component}/#{component}/#{component}/#{id}$} then
|
||||||
{ :module => $1, :controller => $2, :action => $3, :id => $4 }
|
{ :module => $1, :controller => $2, :action => $3, :id => $4 }
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.modules(module_pattern = '[^.]+')
|
||||||
|
path = RAILS_ROOT + '/app/controllers'
|
||||||
|
Dir.entries(path).grep(/^#{module_pattern}$/).find_all {|e| File.directory?("#{path}/#{e}")}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue