Okay, just a follow up question: is there an automatic way to make an
array of all controller names? So that I could use this in the user
model to validate the user doesn't type in any of the controller
names.
(This is a continued conversation of one that asked about making
routes this way:
domain.com/username
but still retaining the functionality to send the user to a controller
if they typed:
@conts_and_meths =
controllers = Dir.new("#{RAILS_ROOT}/app/controllers").entries
controllers.each do |controller|
if controller =~ /_controller/ and not controller.index("\.swp")
then
cont = controller.camelize.gsub(".rb","")
meths = (eval("#{cont}.new.methods") -
ApplicationController.methods - Object.methods -
ApplicationController.new.methods).sort
@conts_and_meths << [cont, meths]
end
This gives you the methods too, but you can see how you would just get
the controllers if you wanted. Careful, this is not stuff you want to
expose to everybody.
@conts_and_meths =
controllers = Dir.new("#{RAILS_ROOT}/app/controllers").entries
controllers.each do |controller|
if controller =~ /_controller/ and not controller.index("\.swp")
then
cont = controller.camelize.gsub(".rb","")
meths = (eval("#{cont}.new.methods") -
ApplicationController.methods - Object.methods -
ApplicationController.new.methods).sort
@conts_and_meths << [cont, meths]
end
This gives you the methods too, but you can see how you would just get
the controllers if you wanted. Careful, this is not stuff you want to
expose to everybody.