Home > Articles > Programming > Ruby

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Using Literal URLs

You can, if you wish, hard-code your paths and URLs as string arguments to link_to, redirect_to, and friends. For example, instead of this:

<%= link_to "Help", :controller => "main", :action => "help" %>

You can write this:

<%= link_to "Help", "/main/help" %>

However, using a literal path or URL bypasses the routing system. If you write literal URLs, you're on your own to maintain them. (You can of course use Ruby's string interpolation techniques to insert values, if that's appropriate for what you're doing, but really stop and think about whether you are reinventing Rails functionality if you go down that path.)

  • + Share This
  • 🔖 Save To Your Account