@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.
On Feb 26, 8:49 pm, Ramon Tayag <[email protected]> wrote:
> 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:
>
> domain.com/controllername
>
> Ramon Tayag
>
> On Thu, Feb 26, 2009 at 5:34 PM, Chris Kottom <[email protected]> wrote:
> > Not sure I understand the behavior you're after completely, but should be
> > able to do this by specifying a named route in your routes file before the
> > default ones.
>
> > Ex:
> > map.user_profile ':username', :controller => 'users', :action => 'show'
> > map.connect ':controller/:action/:id'
> > ...
>
> > This will have the effect, however, of matching any incoming request with
> > only one string. So you won't be able to have another route like:
>
> > map.user_profile ':username', :controller => 'users', :action => 'show'
> > map.group_profile ':groupname', :controller => 'groups', :action =>
> > 'show'
>
> > All requests here meant for either of these would be sent to the
> > UsersController#show because it appears first in the routes file.
>
> > Hope this answers your question.
>
> > On Thu, Feb 26, 2009 at 4:08 AM, Ramon Tayag <[email protected]> wrote:
>
> >> Hey everyone!
>
> >> Is there a way of saying something like this in the routes file (note
> >> that map.connect :controller/:action/:id is my last pattern):
> >> "If the controller you specified doesn't exist, then go to the next
> >> pattern"
>
> >> I want this because if users type in domain.com/noncontrollername, I'd
> >> like the app to render or forward the user to
> >> domain.com/profiles/noncontrollername. So, for example, if my
> >> username is ramon, and I type domain.com/ramon, I will see my profile.
>
> >> If this is not possible, what's a good way of doing this? :)
>
> >> Thanks!
> >> Ramon
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---