Thursday, June 30, 2011

undefined method `hash_for_... Solved.

Ever get a nasty error like this?
And I am on the controls page                        # features/step_definitions/web_steps.rb:44
      undefined method `hash_for_new_admin_organization_path' for # (ActionView::Template::Error)
      /Users/daze/.rvm/gems/ruby-1.9.2-p180@rails31/gems/actionpack-3.1.0.rc4/lib/action_dispatch/routing/polymorphic_routes.rb:133:in `polymorphic_url'
      /Users/daze/.rvm/gems/ruby-1.9.2-p180@rails31/gems/actionpack-3.1.0.rc4/lib/action_dispatch/routing/polymorphic_routes.rb:140:in `polymorphic_path'
      /Users/daze/.rvm/gems/ruby-1.9.2-p180@rails31/gems/actionpack-3.1.0.rc4/lib/action_view/helpers/url_helper.rb:111:in `url_for'
      /Users/daze/.rvm/gems/ruby-1.9.2-p180@rails31/gems/actionpack-3.1.0.rc4/lib/action_view/helpers/url_helper.rb:242:in `link_to'
      ./app/views/admin/organizations/index.html.erb:4:in `_app_views_admin_organizations_index_html_erb___2726815532635892939_2153996520'
No worries.  You probably just forgot something in your routes.rb file.
In my case, I had
<%= link_to "New Organization", new_admin_organization_path %>
in my view.  Sure enough, I hadn't specified the new admin organization path in my routes file.

Solution: put the following in my routes file:
namespace :admin do
  resources :organizations
end
If you find this helpful, feel free to comment below :].

No comments:

Post a Comment

Please be considerate in what you say.