views:

102

answers:

2

Is there a way to look up the HTML for a given controller action? For example, I would like to be able to associate GET with index and PUT with update. I want to be able to do this dynamically based on the routes.

I can get the action methods for each controller using Controller.action_methods, but this returns a set of strings of action methods. Ideally what I would like is a hash of the form: {:action => :verb}.

A: 

:method is part of a :conditions hash you can pass in to map.connect

  map.connect 'post/:id', :controller => 'posts', :action => 'create_comment',
              :conditions => { :method => :get }
Matt Briggs
I'm looking to essentially query the map to find the method for an action. So in your example I would like to be able to start with "create_comment" and have a way to find :post.
Bryan Ward
+3  A: 

Read the rake routes task, that will provide insight:

e.g:

users GET    /users(.:format)     {:controller=>"users", :action=>"index"}

I assume this is what you are after?

Omar Qureshi
That is the data I'm looking for indeed, but now how I want to get it. I'm trying to generate simple test cases for all of my actions which require user authentication. See my previous question: http://stackoverflow.com/questions/1137589/is-it-possible-and-or-advisable-to-generate-tests-dynamically-in-rails . I'm trying to query the Controller for it's actions and find what verb they are associated to produce the actions variable in that example.
Bryan Ward
/Library/Ruby/Gems/1.8/gems/rails-2.3.2/lib/tasks/routes.rake
Omar Qureshi