No route matches [GET] "demo / hello"

Ruby is currently running on the guide rails, and I seem to have hit lightly. I duplicated the view in one of my folders:

hello.html.erb as well as index.html.erb

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

+4
source share
2 answers

Add

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

to your .rb routes

For instance:

application / controllers / demos_controller.rb:

 class DemosController < ApplicationController def hello end end 

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

 <p>Hello World</p> 

config / routes.rb:

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

UPDATE: From comments: read the guide on guides for more details: http://guides.rubyonrails.org/routing.html

+14
source

get 'your url' to: 'yourcontroller # youraction' for example.

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

Source: https://habr.com/ru/post/1501017/


All Articles