简体   繁体   中英

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 :

Creating a RESTful route will also make available a pile of helpers within your application

and then they list some helpers like photos_url , photos_path , etc.

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 . 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. For example app.users_path will return /users/

So for your example type app.entries_url for the full URL - or app.entries_path for its relative path within the console.

命令行中的rake routes应该为您提供该列表。

我想这可能就是你要找的...... http://topfunky.com/clients/peepcode/REST-cheatsheet.pdf

You can access other helpers in the console by prepending "helper."; ie. helper.progress_box (assuming #progress_box exists of course)

从内存中,您无法出于某种原因从控制台调用url / path助手。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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