jonleighton / focused_controller

MIT License
468 stars 27 forks source link

Weird path bug that displays wrong error #19

Closed krainboltgreene closed 12 years ago

krainboltgreene commented 12 years ago

Lets say you have these routes:

Blog::Application.routes.draw do
  focused_controller_routes do
    resources :sessions, only: [:new, :create, :destroy]

    resources :accounts do
      resources :posts
      resources :ideas
    end

    root to: "PagesController::Splash"
  end
end

And now you want to link to the idea form:

"Hello, make a new #{link_to "idea", new_account_idea_path}"

Now this will error out, saying:

ActionController::RoutingError (No route matches {:action=>"run"}):
   app/helpers/accounts_helper.rb:19:in `no_ideas_text'
   app/views/accounts/_no_ideas.html.slim:1:in   
      `_app_views_accounts__no_ideas_html_slim___4495721604514828093_70275587376260'
   app/views/accounts/show.html.slim:7:in
       `_app_views_accounts_show_html_slim__1164712277643331339_70275587639940'

The error page is Rail's "bad route error", so it wont even show the last 4 lines of that error just the routing erro text.

The "problem" here is that I forgot to provide an account_id:

new_account_idea_path(account)

But it doesn't recognize that.

jonleighton commented 12 years ago

Could you provide an example application which exhibits this bug please?

jonleighton commented 12 years ago

I've looked into this a bit. The lack of backtrace on the error page is a rails issue that will be solved in 4.0: rails/rails#6131. There was also a change for rails 4.0 which tells the user which parts of the url are missing.

I might be able to make the "no route matches" message better though...

jonleighton commented 12 years ago

Dealt with by e6e13e7