[英]routing error for root and get pages
I am developing a rails app and This is my first time working with ruby or any server-side programming language. 我正在开发Rails应用程序,这是我第一次使用ruby或任何服务器端编程语言。 I connected to localhost:3000 and everything went well. 我连接到本地主机:3000,一切顺利。 I went to change the routing for my home page as well as create some new ones but I'm having an issue of gettign them to preview and I keep Getting error messages. 我去更改了主页的路由并创建了一些新的路由,但是我遇到了让它们预览的问题,而且我一直在获取错误消息。 Here is the snippet from my routes.rb file 这是我的routes.rb文件中的片段
My routes.rb 我的routes.rb
Rails.application.routes.draw do root 'pages#home' get 'about' => 'pages#about' post 'forum' => 'pages#forum' get 'contact-us' => 'pages#contact-us' end
I'm still relatively new To programming as well as stack overflow so I can't embed images yet So it will only have a link. 我对编程和堆栈溢出还比较陌生,所以我还不能嵌入图像,因此它只有一个链接。 Any help would be appreciated. 任何帮助,将不胜感激。 Thank you! 谢谢!
1 - Try to avoid fat arrow
1-尽量避免fat arrow
2- Controller name should not contain -(dash) instead use _(Underscore) example(contact-us should be contact_us) 2-控制器名称不应包含-(破折号),而应使用_(下划线)示例(contact-us应为contact_us)
Rails.application.routes.draw do Rails.application.routes.draw做
root 'pages#home'
get '/about', to: 'pages#about', as: :about
post '/forum', to: 'pages#forum', as: :forum
get '/contact_us', to: 'pages#contact_us', as: :contact_us
end 结束
3- After changing this run rake routes
at your console in your project directory , you will get list of routes 3-在项目目录中的控制台上更改此运行rake routes
后,您将获得路径列表
4- you can now use routes helper of prefix_path
example (root_path, about_path or forum_path, contact_path) 4-您现在可以使用prefix_path
示例的路由助手(root_path,about_path或forum_path,contact_path)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.