简体   繁体   中英

rails heroku error: no route defined, but route is there (The page you were looking for doesn't exist.)

I am getting a strange error on heroku. So I have an adress ressource that belongs to a user. A user can have multiple adresses, eg shipping and billing.

of course I have

  resources :adresses

in my routes and all (scaffolded) REST controller actions.

now in my view I have the following statement:

<%= button_to "Edit", edit_adress_path(@adress), :class => "edit_adress funkybutton" %>

which generates the following html:

<form class="button_to" action="/adresses/7/edit?locale=en" method="post"><div><input type="submit" value="Edit" class="edit_adress funkybutton"><input type="hidden" value="d/s1KOUtYao+ieqJN3xAz2jrmGPcvF06LjKKHxnFc+o=" name="authenticity_token"></div></form>

Now whenever I click that button, I get the an error page on heroku saying

The page you were looking for doesn't exist.

You may have mistyped the address or the page may have moved.

When I type heroku logs I get:

2012-03-12T18:49:02+00:00 app[web.1]: Started POST "/adresses/7/edit?locale=en" for 85.177.82.243 at 2012-03-12 11:49:02 -0700
2012-03-12T18:49:02+00:00 app[web.1]: 
2012-03-12T18:49:02+00:00 app[web.1]: 
2012-03-12T18:49:02+00:00 app[web.1]: ActionController::RoutingError (No route matches "/adresses/7/edit"):

which seems very odd to me. Even stranger is that when I click in my browsers adress bar after and hit enter, it displays the edit form just fine. So it works, but every single time I click on the button I get this error message. I have no idea whatsoever could be causing the error and hope somebody can help. Thanks!

Btw. I am on Rails 3.0.5

The button_to is creating a POST request to /addresses/7/edit which resources doesn't define a route for. When you manually go to the link in your browser it's creating a GET request, which routes to the edit action.

You can change the button_to call to use a GET method:

<%= button_to "Edit", edit_adress_path(@adress), :class => "edit_adress funkybutton", :method => :get %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM