ActionController::RoutingError (No route matches [GET] "/api/v1/contacts"): Rails + React

26 views Asked by At

I am creating a hybrid architecture single page website using Rails 7.1.2 and React on the Frontend. Long story short I am using Vite and set up my frontend using an api using my contacts_controller. Api was working fine, I changed some settings and now all pages work except the one pulling all contacts from the api. I've tried any close solution on this and am still getting this error:

ActionController::RoutingError (No route matches [GET] "/api/v1/contacts"):

I have routes set up in a AppRoutes.jsx file under frontend/src/components and this was working just fine before and this is my vite.config.js file

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
})

i've also tried many versions of routes.rb but this is most recent. I've also tried other suggestions from SO posts like this but not getting any results. Any help would be great!! Many thanks in advance

Rails.application.routes.draw do
  # Devise routes for authentication
  devise_for :users, controllers: {
    sessions: 'users/sessions'
  }

  # API routes within the /api/v1 namespace
  namespace :api do
    namespace :v1 do
      resources :contacts
    end
  end

  # Health check route
  get "up" => "rails/health#show", as: :rails_health_check
  
  # Serve React application from the Rails public directory
  # for any routes not matched above
  get '*path', to: 'application#fallback_index_html', constraints: ->(request) {
    !request.xhr? && request.format.html?
  }
  
  # The root path routed to fallback_index_html to serve the React app
  root 'application#fallback_index_html'
end

I am trying to set up a 'contacts' page where a user can see all contacts that were submitted via a contact me form.

0

There are 0 answers