POST request on Heroku does not work

I have the following problem. The web service sends a JSON POST request to my Heroku application, and I want to parse it.

If I look at Heroku logs, I see that there was a POST request, but it received an error

ActionController::RoutingError (No route matches....)

But the GET request works fine, with no errors.

I am new to Rails, so I don’t know what happened. Any ideas?

+3
source share
1 answer

All paths (URLs) with corresponding HTTP verbs and other related restrictions must be declared in config/routes.rb.

# config/routes.rb (Rails 3)
MyApp::Application.routes.draw do

  get 'my-service' => 'service#index' # ServiceController#index
  post 'my-service' => 'service#update' # ServiceController#update

end

Once the routes are defined, Rails will respond to the corresponding verb / path argument as you specified - usually by loading the controller and starting the specified action.

# app/service_controller.rb
class ServiceController < ApplicationController

  def index
    # do reading/displaying stuff here
  end

  def update
    # do updating stuff here
  end

end
+3

Source: https://habr.com/ru/post/1778597/


All Articles