37

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
Ethan
  • 57,819
  • 63
  • 187
  • 237

5 Answers5

66

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.

John Topley
  • 113,588
  • 46
  • 195
  • 237
Tim Knight
  • 8,346
  • 4
  • 33
  • 32
  • 3
    the extra anchovies is that it does tab completion, e.g., at the console type app.edit[tab] and it lists all routing helper methods beginning with 'edit'. – pduey Sep 30 '11 at 17:26
18

rake routes at the command line should get you that list.

Mike Woodhouse
  • 51,832
  • 12
  • 88
  • 127
  • 4
    Take the first column and append _url to have the full URI or _path to have an URI not including the domain name. – Vincent Robert Jan 12 '09 at 00:28
  • 4
    Is there any way to generate a list of helpers, with _url and _path and parameters written explicitly? Would be most helpful in the case of nested resources, to see clearly what parameters each helper takes, if any. – Magne Feb 23 '11 at 11:51
3

I think this may be what you are looking for ... http://topfunky.com/clients/peepcode/REST-cheatsheet.pdf

DanSingerman
  • 36,066
  • 13
  • 81
  • 92
1

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

JeffH
  • 10,254
  • 2
  • 27
  • 48
Matt Darby
  • 6,294
  • 4
  • 27
  • 35
-6

From memory, you can't call url/path helpers from the console for some reason.

madlep
  • 47,370
  • 7
  • 42
  • 53