I'm currently working on implementing Geokit into my project. I want to take the info that a user enters onto the create website, geocode the address, and create the entry with the new latitude and longitude created. However, lat or long won't be entered by the user because our geokit will do it for them. Overall, when the user presses the "Create" button, our controller should take all the info (assuming it's been validated) geocode the given address, and use the generated lat and long to create the new entry. I have some general idea how to but not exactly sure if directly changing the controller is the right method to do so. I've included my controller code for visual help. Many thanks in advance!
Overall question - Where do you put the method for geocoding an address and automatically using the generated lat and long to create the rest of the data entry?
class PocsController < ApplicationController
# GET /pocs # GET /pocs.json def index @pocs = Poc.all @pocs = Poc.find(:all) @pocs.sort! { |a,b| a.name.downcase <=> b.name.downcase }
respond_to do |format|
format.html # index.html.erb
format.json { render json: @pocs }
end
end
# GET /pocs/1 # GET /pocs/1.json def show @poc = Poc.find(params[:id]) @pocs = Poc.all
respond_to do |format|
format.html # show.html.erb
format.json { render json: @poc }
end
end
# GET /pocs/new # GET /pocs/new.json def new @poc = Poc.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @poc }
end
end
# GET /pocs/1/edit def edit @poc = Poc.find(params[:id]) end
# POST /pocs # POST /pocs.json def create @poc = Poc.new(params[:poc])
respond_to do |format|
if @poc.save
format.html { redirect_to @poc, notice: 'Poc was successfully created.' }
format.json { render json: @poc, status: :created, location: @poc }
else
format.html { render action: "new" }
format.json { render json: @poc.errors, status: :unprocessable_entity }
end
end
end
# PUT /pocs/1 # PUT /pocs/1.json def update @poc = Poc.find(params[:id])
respond_to do |format|
if @poc.update_attributes(params[:poc])
format.html { redirect_to @poc, notice: 'Poc was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @poc.errors, status: :unprocessable_entity }
end
end
end
# DELETE /pocs/1 # DELETE /pocs/1.json def destroy @poc = Poc.find(params[:id]) @poc.destroy
respond_to do |format|
format.html { redirect_to pocs_url }
format.json { head :no_content }
end
end end