Skip to content

Instantly share code, notes, and snippets.

@jacobo
Created July 28, 2009 17:41
Show Gist options
  • Save jacobo/157553 to your computer and use it in GitHub Desktop.
Save jacobo/157553 to your computer and use it in GitHub Desktop.
#Routes:
ActionController::Routing::Routes.draw do |map|
# restful routes
map.resources :users
# default routes
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
#Controller:
class UsersController < ApplicationController
def index
render :text => "url for show: #{url_for(:action => 'show', :id => 1)}, url for login: #{url_for(:action => 'login')}"
end
def show
render :text => "Show action called with id #{params[:id]}"
end
def login
render :text => "Login action called"
end
end
#Notes:
# So then if I hit the index action, I see:
"url for show: http://localhost:3000/users/1, url for login: http://localhost:3000/users/login"
# But if I then go to that URL for login (http://localhost:3000/users/login), it hits the show action:
"Show action called with id login"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment