Ruby-on-rails 没有路由匹配 [GET] "demo/hello"

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18667326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:40:08  来源:igfitidea点击:

No Route Matches [GET] "demo/hello"

ruby-on-railsruby

提问by Geno Diaz

Currently running through a ruby on rails guide and I seem to have hit a slight snag. I duplicated a view in one of my view folders:

目前正在运行 ruby​​ on rails 指南,我似乎遇到了轻微的障碍。我在我的一个视图文件夹中复制了一个视图:

hello.html.erb and index.html.erb

hello.html.erb 和 index.html.erb

When trying to access it via browser (localhost:3000/demo/"...") Only the original demo/index works but demo/hello has "No Route Matches"

当试图通过浏览器访问它时 (localhost:3000/demo/"...") 只有原始演示/索引有效,但演示/hello 有“没有路由匹配”

回答by Matthias

Add

添加

 get "demo/hello" => "your-controller#your/action"

to your routes.rb

到你的routes.rb

For example:

例如:

app/controllers/demos_controller.rb:

应用程序/控制器/demos_controller.rb:

class DemosController < ApplicationController

  def hello
  end

end

app/views/demos/hello.html.erb:

应用程序/视图/演示/hello.html.erb:

<p>Hello World</p>

config/routes.rb:

配置/routes.rb:

get "demo/hello" => "demos#hello"

UPDATE:From the comments: check out the rails guide for more details: http://guides.rubyonrails.org/routing.html

更新:来自评论:查看 Rails 指南以获取更多详细信息:http: //guides.rubyonrails.org/routing.html

回答by Oktay Ergun

get 'your url path', to: 'yourcontroller#youraction' eg.

获取“您的网址路径”,到:“您的控制器#youraction”,例如。

get '/demos/hello', to: 'demos#hello'