[英]Rails: how do you access RESTful helpers?
I'm trying to work through this guide to Rails routing , but I got stuck in section 3.3 : 我正在尝试通过本指南来完成Rails路由 ,但我在第3.3节中遇到了困难:
Creating a RESTful route will also make available a pile of helpers within your application
创建RESTful路由还可以在应用程序中提供一堆帮助程序
and then they list some helpers like photos_url
, photos_path
, etc. 然后他们列出了一些帮手,如
photos_url
, photos_path
等。
My questions: 我的问题:
Where can I find the complete list of helpers that is "made available?" 我在哪里可以找到“提供”的完整助手列表?
Is there a way to call the helpers in the console? 有没有办法在控制台中调用助手? I created an app, then opened up the console with
script/console
. 我创建了一个应用程序,然后用
script/console
打开了script/console
。 I tried to call one of the helpers on the console like this: 我试着像这样调用控制台上的一个助手:
>> entries_url
But got: 但得到了:
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. 你有几个问题,其中大部分已经被下面的人回答了。
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. 只需输入
app.[route_helper]
,它就会响应路径。 For example app.users_path
will return /users/
例如,
app.users_path
将返回/users/
So for your example type app.entries_url
for the full URL - or app.entries_path
for its relative path within the console. 因此,对于你的榜样型
app.entries_url
的完整URL -或app.entries_path
的控制台内的相对路径。
命令行中的rake routes
应该为您提供该列表。
我想这可能就是你要找的...... http://topfunky.com/clients/peepcode/REST-cheatsheet.pdf
You can access other helpers in the console by prepending "helper."; 您可以通过添加“helper”来访问控制台中的其他帮助程序。 ie.
即。 helper.progress_box (assuming #progress_box exists of course)
helper.progress_box(假设#progress_box当然存在)
从内存中,您无法出于某种原因从控制台调用url / path助手。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.