Skip to content

Instantly share code, notes, and snippets.

@rangerscience
Created March 12, 2011 06:51
Show Gist options
  • Save rangerscience/867099 to your computer and use it in GitHub Desktop.
Save rangerscience/867099 to your computer and use it in GitHub Desktop.
Routes
class CitiesController < ApplicationController
# GET /cities
# GET /cities.xml
def index
@cities = City.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @cities }
end
end
# GET /cities/1
# GET /cities/1.xml
def show
@city = City.find(params[:id])
@county = County.find(@city.county_id)
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @city }
end
end
# GET /cities/new
# GET /cities/new.xml
def new
@city = City.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @city }
end
end
# GET /cities/1/edit
def edit
@city = City.find(params[:id])
end
# POST /cities
# POST /cities.xml
def create
@city = City.new(params[:city])
respond_to do |format|
if @city.save
format.html { redirect_to(@city, :notice => 'City was successfully created.') }
format.xml { render :xml => @city, :status => :created, :location => @city }
else
format.html { render :action => "new" }
format.xml { render :xml => @city.errors, :status => :unprocessable_entity }
end
# PUT /cities/1
# PUT /cities/1.xml
def update
@city = City.find(params[:id])
respond_to do |format|
if @city.update_attributes(params[:city])
format.html { redirect_to(@city, :notice => 'City was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @city.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /cities/1
# DELETE /cities/1.xml
def destroy
@city = City.find(params[:id])
@city.destroy
respond_to do |format|
format.html { redirect_to(cities_url) }
format.xml { head :ok }
end
end
end
class City < Place
belongs_to :county, :class_name => "Place", :foreign_key => 'place_id'
alias_column "county_id" => "place_id"
IpdbUs::Application.routes.draw do
resources :cities
resources :places
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment