Stubs for AJAX posts

This commit is contained in:
Erik Michaels-Ober 2011-03-05 09:22:42 -08:00
parent 27fc84552d
commit 4f0fe7d428
7 changed files with 58 additions and 20 deletions

View File

@ -0,0 +1,35 @@
class MainController < ApplicationController
def index
@zoom = 15
# Default coordinates: Boston center
@lat, @lng = 42.358431, -71.059773
@hydrants = []
address, city_state = params[:address], params[:city_state]
if address && city_state
@zoom = 18
@lat, @lng = Address.find_lat_lng("#{address}, #{city_state}")
@hydrants = Hydrant.find_closest(@lat, @lng)
end
end
def sign_up
@data = {"email" => params[:email], "name" => params[:name]}
respond_to do |format|
format.json{render :json => @data}
end
end
def sign_in
@data = {"email" => params[:email]}
respond_to do |format|
format.json{render :json => @data}
end
end
def forgot_password
@data = {"email" => params[:email]}
respond_to do |format|
format.json{render :json => @data}
end
end
end

View File

@ -1,14 +0,0 @@
class WelcomeController < ApplicationController
def index
@zoom = 15
# Default coordinates: Boston center
@lat, @lng = 42.358431, -71.059773
@hydrants = []
address, city_state = params[:address], params[:city_state]
if address && city_state
@zoom = 18
@lat, @lng = Address.find_lat_lng("#{address}, #{city_state}")
@hydrants = Hydrant.find_closest(@lat, @lng)
end
end
end

View File

@ -78,6 +78,12 @@
$('.choose_password_label').removeClass('error', 500);
$('.choose_password').removeClass('error', 500);
}
if(errors.length > 0) {
errors[0].focus();
} else {
$.post('/sign_up.json', $(this).serialize(), function(data) {
});
}
} else if($(this).data('state') === 'existing') {
if($('.password').val() === '') {
errors.push($('.password'));
@ -87,11 +93,19 @@
$('.password_label').removeClass('error', 500);
$('.password').removeClass('error', 500);
}
if(errors.length > 0) {
errors[0].focus();
} else {
$.post('/sign_in.json', $(this).serialize(), function(data) {
});
}
} else if($(this).data('state') === 'forgot_password') {
}
if(errors.length > 0) {
errors[0].focus();
} else {
if(errors.length > 0) {
errors[0].focus();
} else {
$.post('/forgot_password.json', $(this).serialize(), function(data) {
});
}
}
return false;
});

View File

@ -1,4 +1,7 @@
AdoptAHydrant::Application.routes.draw do
get "javascripts/:action" => "javascripts#action"
root :to => "welcome#index"
get "/javascripts/:action" => "javascripts#action"
post "/sign_up.:format" => "main#sign_up"
post "/sign_in.:format" => "main#sign_in"
post "/forgot_password.:format" => "main#forgot_password"
root :to => "main#index"
end