Mike Garey
2006-Nov-04 02:22 UTC
[Rails] Question about named routes - getting "No url can be generated for the hash"
So I''ve decided to clean up the structure of my rails app and have been using named routes and storing certain controllers underneath other controllers where appropriate.. For example, I have an AdminController, as well as a ContentController. I decided to make ContentController a subclass of the AdminController, because the content management portion of the site is only accessible to administrators, and that way I can use the following hierarchy: app/controllers/admin/content_controller.rb. I also have the following routes defined: # Content Routes map.with_options(:controller => ''admin/content'') do |content| content.content_index ''admin/content'', :action => ''index'' content.content_list_faq ''admin/content/faq/list'', :action => ''list_faq'' content.content_edit_faq ''admin/content/faq/edit/:id'', :action => ''edit_faq'' content.content_new_faq ''admin/content/faq/new'', :action => ''new_faq'' content.content_remove_faq ''admin/content/faq/remove/:id'', :action => ''remove_faq'' .... end but now when I do something like this in list_faq.rhtml: <%= start_form_tag(:action => ''new_faq_section'') %> I get the following error: No url can be generated for the hash {:action=>"new_faq_section", :controller=>"admin/content"} I can get past this by using another named route, for example: content.content_new_faq_section ''admin/content/faq/new_faq_section'', :action => ''new_faq_section'' but I wanted to know why I can''t just use :action => ''new_faq_section''.. When using named routes, does _every_ route have to have a name? Can you not intermix named routes with explicit routes (ie those with :action => my_action, :controller => ''my_controller'')? Or am I doing something wrong? Thanks Mike