Rails:您如何访问RESTful帮助器? [英] Rails: how do you access RESTful helpers?
问题描述
我正在尝试阅读本 Rails路由指南,但是我陷入了困境 3.3 部分:
I'm trying to work through this guide to Rails routing, but I got stuck in section 3.3:
创建RESTful路由还将在您的应用程序中提供一堆帮助程序
Creating a RESTful route will also make available a pile of helpers within your application
然后他们列出了一些帮助程序例如 photos_url
, photos_path
等。
and then they list some helpers like photos_url
, photos_path
, etc.
我的问题:
在哪里可以找到可用的助手的完整列表?
Where can I find the complete list of helpers that is "made available?"
是否有一个控制台中调用助手的方法?我创建了一个应用程序,然后使用 script / console
打开了控制台。我试图像这样在控制台上调用一个助手:
Is there a way to call the helpers in the console? I created an app, then opened up the console with script/console
. I tried to call one of the helpers on the console like this:
>> entries_url
但是得到了:
NameError: undefined local variable or method `entries_url' for #<Object:0x349a4>
from (irb):8
推荐答案
您其中有几个问题,其中大多数已经被以下人员回答。
You have several questions in there, most of which have already been answered by people below.
对一个尚未完全解决的问题的答案是:是的,您可以使用脚本/控制台以查看路线。只需输入 app。[route_helper]
,它将使用路径进行响应。例如, app.users_path
将返回 / users /
The answer to one that wasn't fully addressed however, is: yes you can use the script/console to see where your routes go. Just type in app.[route_helper]
and it will respond with the path. For example app.users_path
will return /users/
因此,在您的示例中,输入 app.entries_url
作为完整URL-或 app.entries_path
作为其相对路径控制台。
So for your example type app.entries_url
for the full URL - or app.entries_path
for its relative path within the console.
这篇关于Rails:您如何访问RESTful帮助器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!