Ruby on rails 路径助手 [英] Ruby on rails path helpers

查看:32
本文介绍了Ruby on rails 路径助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个小问题,但是为什么,如果你在 RoR 中使用脚手架,你可以在链接标签中使用像new_model name here_path"这样的行,但不使用脚手架,我得到一个名称错误?例如,我有一个使用基本 CRUD 操作的简单地址簿应用程序.我是一个 RoR 初学者,但想构建一个没有脚手架的应用程序,而这些东西似乎不起作用.我将我的 config/routes.rb 和 app/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? For example, I have a simple address book app that uses basic CRUD operations. I am a RoR beginner but wanted to build an app without scaffolding and these kind of things don't seem to work. I compared my config/routes.rb and app/helpers/* with those in a scaffolded app and they are no different. What am I missing?

推荐答案

Scaffolding 在 routes.rb 文件中设置资源路由.资源路由为您提供路径和 url 帮助程序.当您不使用脚手架时,不会添加路线,您必须手动完成.

Scaffolding sets up resource routes in the routes.rb file. The resource routes are what give you the path and url helpers. 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

其中 :models 是您的模型之一的复数名称.

where :models is the plural name of one of your models.

这篇关于Ruby on rails 路径助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆