没有路线匹配 [GET] "staticpage.html"
No route matches [GET] "staticpage.html"
我正在尝试设置一个新的静态页面和以后的动态页面。
我在 app/controllers/
中创建了 detailpages_controller.rb
。我里面有:
class DetailPagesController < ApplicationController
def show
render
end
end
然后,在config/routes.rb
我有:
Rails.application.routes.draw do
root 'welcome#index'
DetailPagesController.action_methods.each do |action|
get "/#{action}", to: "detailpages##{action}", as: "#{action}_page"
end
end
在 app/viewes/pages
上有一个 detailpages.html.erb
文件只包含一个 <h2>Hello World</h2>
当我去 http://localhost:3000/detailpages.html
我得到:
No route matches [GET] "/detailpages.html"
如果我只是 localhost:3000
我的 index.html
工作得很好,但我不能,为了我的生活,添加这个新页面以便我以后可以 link 到它。
有人可以告诉我我做错了什么吗?
您可以使用
映射到 detailpages.html
get 'detailpages.html' => 'detail_pages#show', as: :detail_page
您还需要编辑 DetailPagesController
的名称,它应该是 detail_pages_controller.rb
。每个单词用_
隔开,称为蛇形套管。
你还需要一个相应的视图,放在app/views/detail_pages/show.html.erb
我正在尝试设置一个新的静态页面和以后的动态页面。
我在 app/controllers/
中创建了 detailpages_controller.rb
。我里面有:
class DetailPagesController < ApplicationController
def show
render
end
end
然后,在config/routes.rb
我有:
Rails.application.routes.draw do
root 'welcome#index'
DetailPagesController.action_methods.each do |action|
get "/#{action}", to: "detailpages##{action}", as: "#{action}_page"
end
end
在 app/viewes/pages
上有一个 detailpages.html.erb
文件只包含一个 <h2>Hello World</h2>
当我去 http://localhost:3000/detailpages.html
我得到:
No route matches [GET] "/detailpages.html"
如果我只是 localhost:3000
我的 index.html
工作得很好,但我不能,为了我的生活,添加这个新页面以便我以后可以 link 到它。
有人可以告诉我我做错了什么吗?
您可以使用
映射到detailpages.html
get 'detailpages.html' => 'detail_pages#show', as: :detail_page
您还需要编辑 DetailPagesController
的名称,它应该是 detail_pages_controller.rb
。每个单词用_
隔开,称为蛇形套管。
你还需要一个相应的视图,放在app/views/detail_pages/show.html.erb