0

When you type rake routes in the shell it displays a nice list of routes:

      new_edition GET    /editions/new(.:format)           editions#new
     edit_edition GET    /editions/:id/edit(.:format)      editions#edit
         edition GET    /editions/:id(.:format)           editions#show
                 PUT    /editions/:id(.:format)           editions#update
              DELETE /editions/:id(.:format)           editions#destroy

This is very helpful but why not show the actual code needed to be used in the app as well for example

 edition GET    /editions/:id(.:format)  editions#show  edition_path()

I am guess it is because there may be more to it then this but the general issue is when I look at the examples give for the routes I have look up an example of how it is expressly coded to understand what the route means...

akkdio
  • 573
  • 2
  • 5
  • 13

2 Answers2

5

Using xxx_path directly isn't the only option you have.

Rails offers you resourceful way of building urls via polymorpic_path/_url methods. These methods are used by many other helpers, like:

link_to 'Edit', [:edit, @user]     # instead of edit_user_path(@user)
redirect_to Product                # instead of products_path
form_for [@order, @product] do |f| # instead of order_product_path(@order, @product)
visit url_for [:preview, @invoice] # instead of preview_invoice_path(@invoice)

So, by looking at preview_invoice prefix you know what to do, but the exact way is up to you.

jdoe
  • 15,665
  • 2
  • 46
  • 48
  • Thank you jdoe. Your answer helped me understand the options and how why they are presenting what they are in the rake routes command. Really appreciated it. – akkdio Jun 11 '12 at 16:37
  • The question should be closed, but it would be a pity to lose this answer :) – Arsen7 Jun 12 '12 at 10:29
  • @Arsen7 Thanks, your comment is also nonconstructive! :-) – jdoe Jun 12 '12 at 10:36
0

You have all the info needed. The first column tells you the prefix of the name of the route helper (new_edition, for instance). All you need to do is add _path or _url to have the complete method name.

Then, you have some routes with no indication regarding the corresponding helper method name: it's because it matches the same URL as another route, only the HTTP verb (GET, POST) changes. So you'd have to add method: 'delete' for instance to your call.

ksol
  • 11,835
  • 5
  • 37
  • 64