简体   繁体   English

Ruby on rails路径助手

[英]Ruby on rails path helpers

I know this is a minor issue, but why, if you use scaffolding in RoR, can you use lines like 'new_ model name here _path' in link tags, but without using scaffolding, I get a NameError? 我知道这是一个小问题,但是为什么,如果你在RoR中使用脚手架,你可以在链接标签中使用像'new_ model name here _path'这样的行,但是如果不使用脚手架,我会得到一个NameError? For example, I have a simple address book app that uses basic CRUD operations. 例如,我有一个简单的地址簿应用程序,它使用基本的CRUD操作。 I am a RoR beginner but wanted to build an app without scaffolding and these kind of things don't seem to work. 我是一个RoR初学者,但想要构建一个没有脚手架的应用程序,这些东西似乎不起作用。 I compared my config/routes.rb and app/helpers/* with those in a scaffolded app and they are no different. 我比较了我的config / routes.rb和app / helpers / *与脚手架应用程序中的那些,它们没有什么不同。 What am I missing? 我错过了什么?

One way to check your routes and paths is to run: 检查路线和路径的一种方法是运行:

rake routes

It outputs all your routes and paths. 它输出您的所有路线和路径。

Scaffolding sets up resource routes in the routes.rb file. Scaffolding在routes.rb文件中设置资源路由。 The resource routes are what give you the path and url helpers. 资源路由为您提供路径和URL帮助程序。 When you don't use scaffolding the routes aren't added, you must do it by hand. 如果不使用脚手架,则不添加路线,必须手动完成。

Resource Routes can be added like so: 可以像这样添加资源路由:

map.resources :models

where :models is the plural name of one of your models. 其中:models是您的某个模型的复数名称。

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

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