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屋!