我收到错误“uninitialized constant ContactController”

时间:2016-03-19 04:07:39

标签: ruby-on-rails routing

routes.rb文件是

Rails.application.routes.draw do

  root  'pages#home'
  match '/contact', to: 'pages#contact', via: 'get'
  match '/home',    to: 'contact#pages', via: 'get'

pages_controller

class PagesController < ApplicationController
    def home
    end

    def contact
    end

end

我收到路由错误,说“未初始化的常量ContactController”。有谁知道如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

match已弃用。试试

root 'pages#home'
get '/contact', to: 'pages#contact'
get '/home', to: 'pages#home'

答案 1 :(得分:0)

请更改您的routes.rb文件

Rails.application.routes.draw do
  root  'pages#home'
  match '/contact', to: 'pages#contact', via: :get
  match '/home',    to: 'pages#home',    via: :get
end

会工作!!!

Rails 4 match methods必须指定HTTP method否则会RuntimeError &#34;您不应该使用match方法路由器没有指定HTTP方法。 (RuntimeError)&#34;