#34 Named Routes

When you add a custom route, make it a named route so you have url helper methods to easily link to that new route. See episode for details.
# routes.rb
map.resources :projects
map.task_archive 'tasks/:year/:month', :controller => 'tasks', :action => 'archive'
map.home '', :controller => 'projects', :action => 'index'
<!-- projects/index.rhtml -->
<ul>
<% for project in @projects %>
  <li>
    <%= link_to project.name, project_path(project) %>
    | <%= link_to "Edit", edit_project_path(project) %>
    | <%= link_to "Destroy", project_path(project), :method => :delete %>
  </li>
<% end %>
</ul>

<p><%= link_to "New Project", new_project_path %></p>

你可能感兴趣的:(Routes)