ruby-on-railssearchpg-search

No route matches although route is made


I am following the following tutorial, https://www.dailysmarty.com/posts/how-to-add-search-functionality-into-a-rails-api-application .

After managing to complete the entire tutorial, I realised that there are no route that matches "/search". The tutorial did not state how to do routes, hence I have attempted to do one myself by creating the following:

    Rails.application.routes.draw do
      resources :search, only: [:search]
    end

Solution

  • This is not what you want. You need a get route like this:

    get '/your_route', to: 'your_controller#your_action'
    

    So, in your case, search is not a resource. So I would use:

    get '/search', to: 'search#search'
    

    You can find all this info regarding routing on the rails guide.

    I hope this helps!