Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RuntimeError: You should not use the `match` method in your router without specifying an HTTP method

I'm trying to run 'rails console' and I keep getting the following error message:

in normalize_conditions!': You should not use thematchmethod in your router without specifying an HTTP method. (RuntimeError) If you want to expose your action to both GET and POST, addvia: [:get, :post]option. If you want to expose your action to GET, useget` in the router: Instead of: match "controller#action" Do: get "controller#action"

I can't find the solution on Stack Overflow, what should I do?

My routes.rb file is:

Myapp::Application.routes.draw do

  resources :users do
    member do
      get :following, :followers
    end
  end

  resources :sessions,      only: [:new, :create, :destroy]
  resources :microposts,    only: [:create, :destroy]
  resources :relationships, only: [:create, :destroy]

  root to: 'static_pages#home'

  # Named routes:
  match '/signup',  to: 'users#new'
  match '/signin',  to: 'sessions#new'
  match '/signout', to: 'sessions#destroy', via: :delete

  match '/help',    to: 'static_pages#help'
  match '/about',   to: 'static_pages#about'
  match '/contact', to: 'static_pages#contact'

end
like image 225
Bazley Avatar asked Dec 18 '25 01:12

Bazley


1 Answers

sounds like you have an issue in your routes.rb file. Probably the first thing to do is comment any line that you're using a match route in; or, as the error message suggests, add via: [:get, :post] to its options.

Such as:

match 'path', :to => 'controller#action', :via => [:get, :post]
like image 106
Pavling Avatar answered Dec 20 '25 19:12

Pavling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!