简体   繁体   English

没有路线匹配[GET]“/”

[英]No route matches [GET] “/”

I'm new to rails so it may sound quite naive.I'm getting this error 我是铁杆的新手所以听起来很天真。我得到了这个错误

No route matches [GET] "/"

Here is my routes.rb 这是我的routes.rb

MyApp::Application.routes.draw do
    match 'welcome/contact' => 'welcome#index'
end

Here is my controller 这是我的控制器

class WelcomeController < ApplicationController
   def index
      redirect_to :action => :contact
   end
   def contact

   end
end

And i have a contact.html.erb in my app/view/welcome/.What am i doing wrong? 我的app / view / welcome /中有一个contact.html.erb。我做错了什么?

I don't understand what you want to do. 我不明白你想做什么。 But I think you want your view Welcome/contact as your index page, if this is correct, you only have to change your routes.rb file like this: 但我认为您希望将欢迎/联系视图作为索引页面,如果这是正确的,您只需要更改您的routes.rb文件,如下所示:

root to: 'welcome#contact'

and you have to remove the index.html file from the public folder. 并且您必须从公用文件夹中删除index.html文件。

On the other hand, you can read more of rails routes here 另一方面,您可以在此处阅读更多铁路路线

您需要为控制器中的CRUD操作之外的操作创建路径。这将解决所有操作的问题。

match ':controller(/:action)'

What you want to do is to RENDER the contact page, not to redirect to another controller and action. 您要做的是RENDER联系页面,而不是重定向到另一个控制器和操作。

Just put the code in the contact view into the app/views/welcome/index.html.erb file, and live happily. 只需将联系人视图中的代码放入app/views/welcome/index.html.erb文件中,即可幸福地生活。

You need to add a contact action to your WelcomeController 您需要向WelcomeController添加联系人操作

class WelcomeController < ApplicationController
  def index
     redirect_to :action => :contact
  end

  def contact
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM