You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.0 KiB

class MapsController < ApplicationController
# GET /maps
# GET /maps.xml
def index
@maps = Map.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @maps }
end
end
def show
@map = Map.find(params[:id])
respond_to do |format|
format.png do
GoogleMapLocationFetcher.new.fetch([@map.name]) do |loc,image|
dest = Rails.root.join("public/maps/#{@map.id}.png")
FileUtils.mkdir_p(File.dirname(dest))
File.open(dest, 'w') do |f|
f.write(image)
end
send_file(dest)
end
end
end
end
# GET /maps/new
# GET /maps/new.xml
def new
@map = Map.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @map }
end
end
# GET /maps/1/edit
def edit
@map = Map.find(params[:id])
end
# POST /maps
# POST /maps.xml
def create
@map = Map.new(params[:map])
respond_to do |format|
if @map.save
flash[:notice] = 'Map was successfully created.'
format.html { redirect_to(@map) }
format.xml { render :xml => @map, :status => :created, :location => @map }
else
format.html { render :action => "new" }
format.xml { render :xml => @map.errors, :status => :unprocessable_entity }
end
end
end
# PUT /maps/1
# PUT /maps/1.xml
def update
@map = Map.find(params[:id])
respond_to do |format|
if @map.update_attributes(params[:map])
flash[:notice] = 'Map was successfully updated.'
format.html { redirect_to(@map) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @map.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /maps/1
# DELETE /maps/1.xml
def destroy
@map = Map.find(params[:id])
@map.destroy
respond_to do |format|
format.html { redirect_to(maps_url) }
format.xml { head :ok }
end
end
end