Nick Ginanto
Nick Ginanto

Reputation: 32120

Routing error even if routes exists

This is really weird. I am getting a routing error on a link_to that exists on every page

This is my route

resources :users do
    member do
      get :creations_tab, :path => '/creations'
    end

which translates to

creations_tab_user_path  GET     /users/:id/creations(.:format)  users#creations_tab

this is where the error happens

 <li><%= link_to content_tag(:i," ", :class=>"icon-bullhorn")+ " " +"Creations", creations_tab_user_path %></li>

The weird part is this link_to is a link in a navbar that exists on everypage.. some pages it works some don't...

this is the error

ActionController::RoutingError - No route matches {:action=>"creations_tab", :controller=>"users"}:
  (gem) actionpack-3.2.12/lib/action_controller/metal/exceptions.rb:11:in `initialize'
  (gem) actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:533:in `raise_routing_error'
  (gem) actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:529:in `rescue in generate'
  (gem) actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:521:in `generate'
  (gem) actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:562:in `generate'
  (gem) actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:587:in `url_for'
  (gem) actionpack-3.2.12/lib/action_dispatch/routing/url_for.rb:148:in `url_for'
  (gem) actionpack-3.2.12/lib/action_view/helpers/url_helper.rb:107:in `url_for'
  (gem) actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:213:in `creations_tab_user_path'
  app/views/layouts/_header.html.erb:43:in `_app_views_layouts__header_html_erb__541622111_70332144'

Upvotes: 0

Views: 232

Answers (1)

Jesper
Jesper

Reputation: 4555

Since your route is a member route, it will expect to be provided with a user id. So it wouldn't make sense to call the helper with no arguments, as you're doing.

I suspect that somekind of RoR-magic is providing the helper with an argument in some cases - but in reality it shouldn't work.

So give that helper a user or a user id.

Upvotes: 2

Related Questions