Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matching and Routes in Rails

I generated a controller and changed the routes but opening the links yields errors on my local server.

Generating controller and routes

rails generate controller StaticPages home about team contact

Change routes.rb

MyApp::Application.routes.draw do
  root to: 'static_pages#home'

  match '/about',    to: 'static_pages#about'
  match '/team',     to: 'static_pages#team'
  match '/contact',  to: 'static_pages#contact'
end

The root path work but none of the 'about, 'team', or 'contact' links work. This is the error I get:

"You should not use the match method in your router without specifying an HTTP method. If you want to expose your action to both GET and POST, add via: [:get, :post] option. If you want to expose your action to GET, use get in the router: Instead of: match "controller#action" Do: get "controller#action""

Why can't I use 'match'?

like image 310
megashigger Avatar asked Aug 21 '13 22:08

megashigger


1 Answers

match method has been deprecated.

Use get for GET and post for POST.

get '/about', to: 'static_pages#about'

like image 162
Jason Kim Avatar answered Oct 21 '22 22:10

Jason Kim