Ошибка маршрутизации Rails, несмотря на определение маршрута - PullRequest
1 голос
/ 03 февраля 2020

Создание приложения с использованием API-интерфейса RoR и интерфейса React. Когда компонент App. js монтируется, предполагается, что он совершает вызов бэкэнда, извлекая контент для заполнения внешнего интерфейса. По какой-то причине существует ошибка маршрутизации, несмотря на то, что определен маршрут и метод http

App. js> Метод ComponentDidMount ()

  async componentDidMount(){
    await getEvents(this.props.auth)
    .then((res) => {
      return res.json()})
    .then((json) => this.setState({
        events: [...json['events']]
    }))
    .catch((err) => {
      alert('There was an error retrieving events. ERROR: ' + err)
    })
  }

getEvents () - это просто функция, которая возвращает запрос POST API Fetch api на URL моего API.

Файл Route.rb

Rails.application.routes.draw do
  devise_for :user, only: []
  namespace :v1, defaults: { format: :json } do
    resource :login, only: [:create], controller: :sessions
    resource :sign_up, only: [:create], controller: :users
    resource :event, only: [:create, :update, :destroy], controller: :events
    post '/event/event_like' => 'events#userLikes?'
    post '/events' => 'events#index'
    post '/event/like' => 'events#like'
    post '/event/group' => 'events#getGroup'
    delete '/event/unlike' => 'events#unlike'
  end
end

Ошибка, которую я продолжаю получать

ActionController::RoutingError (No route matches [POST] "/v1/events"):

actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.3) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.3) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.3) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.7) lib/rack/method_override.rb:22:in `call'
rack (2.0.7) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.3) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.7) lib/rack/sendfile.rb:111:in `call'
rack-cors (1.0.3) lib/rack/cors.rb:95:in `call'
webpacker (4.0.7) lib/webpacker/dev_server_proxy.rb:29:in `perform_request'
rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
railties (5.2.3) lib/rails/engine.rb:524:in `call'
puma (4.1.0) lib/puma/configuration.rb:228:in `call'
puma (4.1.0) lib/puma/server.rb:664:in `handle_request'
puma (4.1.0) lib/puma/server.rb:467:in `process_client'
puma (4.1.0) lib/puma/server.rb:328:in `block in run'
puma (4.1.0) lib/puma/thread_pool.rb:135:in `block in spawn_thread'

Выполнение маршрутов rails в терминале выдает:

                   Prefix Verb   URI Pattern                                                                              Controller#Action
                 v1_login POST   /v1/login(.:format)                                                                      v1/sessions#create {:format=>:json}
               v1_sign_up POST   /v1/sign_up(.:format)                                                                    v1/users#create {:format=>:json}
                 v1_event PATCH  /v1/event(.:format)                                                                      v1/events#update {:format=>:json}
                          PUT    /v1/event(.:format)                                                                      v1/events#update {:format=>:json}
                          DELETE /v1/event(.:format)                                                                      v1/events#destroy {:format=>:json}
                          POST   /v1/event(.:format)                                                                      v1/events#create {:format=>:json}
      v1_event_event_like POST   /v1/event/event_like(.:format)                                                           v1/events#userLikes? {:format=>:json}
                v1_events POST   /v1/events(.:format)                                                                     v1/events#index {:format=>:json}
            v1_event_like POST   /v1/event/like(.:format)                                                                 v1/events#like {:format=>:json}
           v1_event_group POST   /v1/event/group(.:format)                                                                v1/events#getGroup {:format=>:json}
          v1_event_unlike DELETE /v1/event/unlike(.:format)                                                               v1/events#unlike {:format=>:json}
       rails_service_blob GET    /rails/active_storage/blobs/:signed_id/*filename(.:format)                               active_storage/blobs#show
rails_blob_representation GET    /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
       rails_disk_service GET    /rails/active_storage/disk/:encoded_key/*filename(.:format)                              active_storage/disk#show
update_rails_disk_service PUT    /rails/active_storage/disk/:encoded_token(.:format)                                      active_storage/disk#update
     rails_direct_uploads POST   /rails/active_storage/direct_uploads(.:format)                                           active_storage/direct_uploads#create

Маршрут определен, и все же вызов не проходит. Есть мысли?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...