Skip to content

Instantly share code, notes, and snippets.

@rubiii
Created November 17, 2010 22:43
Show Gist options
  • Save rubiii/704272 to your computer and use it in GitHub Desktop.
Save rubiii/704272 to your computer and use it in GitHub Desktop.
MyApp::Application.routes.draw do
resource :contacts
end
# which creates the following routes:
#
# contacts POST /contacts(.:format) {:controller=>"contacts", :action=>"create"}
# new_contacts GET /contacts/new(.:format) {:controller=>"contacts", :action=>"new"}
# edit_contacts GET /contacts/edit(.:format) {:controller=>"contacts", :action=>"edit"}
# GET /contacts(.:format) {:controller=>"contacts", :action=>"show"}
# PUT /contacts(.:format) {:controller=>"contacts", :action=>"update"}
# DELETE /contacts(.:format) {:controller=>"contacts", :action=>"destroy"}
# this is a "stupid" helper i created to map the rails3 route-syntax to :controller and :action values
module ApplicationHelper
def route_link(name, route, html_options = {})
route = route.split("#")
link_to(name, { :controller => route[0], :action => route[1] }, html_options)
end
end
-# this shows how i would like to use "route-links":
= route_link "New Contact", "contacts#new" # expected output: '<a href="/contacts/new">New Contact</a>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment