small medium large xlarge

02 Jan 2011, 21:15
Gaurav Kalra (1 post)

Hi I am new to RoR and following PragProg (v4) for the same.

In the heading “Linking pages together” (chapter 2), the book says “ If we were to move our application to a different place on the web server, the URLs would no longer be valid. It also encodes assumptions about the Rails URL format into our code; it’s possible a future version of Rails might change this.”

Ans then recommends the use of <%= link_to “Hello”, say_hello_path %> and <%= link_to “Goodbye”, say_goodbye_path %>

Both of them still have “say” and “hello/goodbye” …. Is the assertion by book justified ?

03 Feb 2011, 12:18
Augusto Rodriguez (9 posts)

Hi Gaurav,

I’m no expert, but you can change the “user facing” url in routes.rb and if you use the helper methods, you won’t need to change anything.

for example, if you add the following line in routes.rb in the depot app (which starts on chapter 5) match ‘/:id’ => ‘products#show’

you can access any product by going to http://localhost:3000/[product_id]

so it means that you get a url rewriter extension for free.

–EDIT I just realized that what I wrote doesn’t answer your question in any way… although the answer is related to routes.rb, as it’s used to translate urls to contollers and controllers to urls too.

You must be logged in to comment