MWeber
MWeber

Reputation: 613

Rails POST throws GET error

I have a rails link that's using the POST method:

link_to "Run", forecast_run_path(@forecast), method: :post

to call a defined post route:

  resources :forecasts do
    post :run       
  end   

The route appears in rake routes output as expected:

forecast_run POST   /forecasts/:forecast_id/run(.:format)                                   forecasts#run

And when I inspect the page, the expected post link appears in the page:

<a href="/forecasts/20/run" data-method="post" rel="nofollow" title="Run Forecast">Run Forecast</a>

In dev it works fine, and was good in production until sometime just a few days ago - I can't find any change that seems like it should have broken it. But when I click the link, I get the error ActionController::RoutingError (No route matches [GET] "/forecasts/20/run")

I agree that no GET route matches, but it should be using POST.

This is Ruby 2.1.5, Rails 4.2.0

Upvotes: 0

Views: 48

Answers (2)

MWeber
MWeber

Reputation: 613

To my own embarrassment and for the benefit of anyone else who has the same issue: As I switched among different clients, I didn't notice that on one of them NoScript in Firefox was blocking javascript on that site. Doh!

Upvotes: 1

Ahmad Al-kheat
Ahmad Al-kheat

Reputation: 1795

When you post a run, the form will direct you to the show action where it displays the newly posted run, in your case you don't have a show action for run, so implement a show action and should work fine.

Upvotes: 0

Related Questions