diff --git a/app/controllers/addresses_controller.rb b/app/controllers/addresses_controller.rb
index 366b9ea..a73cd1f 100644
--- a/app/controllers/addresses_controller.rb
+++ b/app/controllers/addresses_controller.rb
@@ -1,6 +1,7 @@
class AddressesController < ApplicationController
respond_to :json
- def index
+
+ def show
@address = Address.find_lat_lng("#{params[:address]}, #{params[:city_state]}")
unless @address.blank?
respond_with @address
diff --git a/app/controllers/contents_controller.rb b/app/controllers/contents_controller.rb
deleted file mode 100644
index d670dfd..0000000
--- a/app/controllers/contents_controller.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-class ContentsController < ApplicationController
- def index
- @hydrant = Hydrant.find_by_id(params[:hydrant_id])
- if @hydrant.adopted?
- if user_signed_in? && current_user.id == @hydrant.user_id
- render(:partial => "thank_you")
- else
- render(:partial => "user_profile")
- end
- else
- if user_signed_in?
- render(:partial => "adoption_form")
- else
- render(:partial => "combo_form")
- end
- end
- end
-end
diff --git a/app/controllers/hydrants_controller.rb b/app/controllers/hydrants_controller.rb
index 9d6a520..e1349ff 100644
--- a/app/controllers/hydrants_controller.rb
+++ b/app/controllers/hydrants_controller.rb
@@ -1,10 +1,25 @@
class HydrantsController < ApplicationController
- respond_to :json
+ def show
+ @hydrant = Hydrant.find_by_id(params[:hydrant_id])
+ if @hydrant.adopted?
+ if user_signed_in? && current_user.id == @hydrant.user_id
+ render(:partial => "users/thank_you")
+ else
+ render(:partial => "users/profile")
+ end
+ else
+ if user_signed_in?
+ render(:partial => "adopt")
+ else
+ render(:partial => "users/new")
+ end
+ end
+ end
- def index
+ def list
@hydrants = Hydrant.find_closest(params[:lat], params[:lng])
unless @hydrants.blank?
- respond_with @hydrants
+ render(:json => @hydrants)
else
render(:json => {"errors" => {"address" => ["Could not find address."]}})
end
diff --git a/app/controllers/javascripts_controller.rb b/app/controllers/javascripts_controller.rb
deleted file mode 100644
index 2081b8a..0000000
--- a/app/controllers/javascripts_controller.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-class JavascriptsController < ApplicationController
- def main
- end
-end
diff --git a/app/views/contents/_thank_you.html.erb b/app/views/contents/_thank_you.html.erb
deleted file mode 100644
index 69aab2e..0000000
--- a/app/views/contents/_thank_you.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-
Thank you for adopting this hydrant!
-<%= render :partial => 'abandon_form' %>
-<%= render :partial => 'sign_out_form' %>
diff --git a/app/views/contents/_adoption_form.html.erb b/app/views/hydrants/_adopt.html.erb
similarity index 91%
rename from app/views/contents/_adoption_form.html.erb
rename to app/views/hydrants/_adopt.html.erb
index 3931d4f..585484c 100644
--- a/app/views/contents/_adoption_form.html.erb
+++ b/app/views/hydrants/_adopt.html.erb
@@ -7,4 +7,4 @@
<%= f.submit "Adopt!", :tabindex => 2, :id => "adoption_form_submit" %>
By adopting this hydrant, you agree to the <%= link_to "Terms of Service", "#", :tabindex => 3 %>.
<% end %>
-<%= render :partial => 'sign_out_form' %>
+<%= render(:partial => 'users/sign_out_form') %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index ce3c692..433da13 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -7,7 +7,7 @@
<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" %>
<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js" %>
<%= javascript_include_tag "https://github.com/scottschiller/Snowstorm/raw/master/snowstorm-min.js" %>
- <%= javascript_include_tag javascripts_main_path %>
+ <%= javascript_include_tag :all %>
<%= csrf_meta_tag %>
diff --git a/app/views/contents/_abandon_form.html.erb b/app/views/users/_abandon_form.html.erb
similarity index 100%
rename from app/views/contents/_abandon_form.html.erb
rename to app/views/users/_abandon_form.html.erb
diff --git a/app/views/contents/_combo_form.html.erb b/app/views/users/_new.html.erb
similarity index 100%
rename from app/views/contents/_combo_form.html.erb
rename to app/views/users/_new.html.erb
diff --git a/app/views/contents/_user_profile.html.erb b/app/views/users/_profile.html.erb
similarity index 73%
rename from app/views/contents/_user_profile.html.erb
rename to app/views/users/_profile.html.erb
index 4afb5ca..9f37dcb 100644
--- a/app/views/contents/_user_profile.html.erb
+++ b/app/views/users/_profile.html.erb
@@ -1,6 +1,6 @@
<%= @hydrant.name ? @hydrant.name.titleize : "This hydrant" %> has been adopted by <%= @hydrant.user.name %>
<%= @hydrant.user.organization.blank? ? nil : "of #{@hydrant.user.organization}
".html_safe %>
<% if user_signed_in? %>
-<%= render :partial => 'steal_form' %>
-<%= render :partial => 'sign_out_form' %>
+<%= render :partial => 'users/steal_form' %>
+<%= render :partial => 'users/sign_out_form' %>
<% end %>
diff --git a/app/views/contents/_sign_out_form.html.erb b/app/views/users/_sign_out_form.html.erb
similarity index 100%
rename from app/views/contents/_sign_out_form.html.erb
rename to app/views/users/_sign_out_form.html.erb
diff --git a/app/views/contents/_steal_form.html.erb b/app/views/users/_steal_form.html.erb
similarity index 100%
rename from app/views/contents/_steal_form.html.erb
rename to app/views/users/_steal_form.html.erb
diff --git a/app/views/users/_thank_you.html.erb b/app/views/users/_thank_you.html.erb
new file mode 100644
index 0000000..8ed4594
--- /dev/null
+++ b/app/views/users/_thank_you.html.erb
@@ -0,0 +1,3 @@
+Thank you for adopting this hydrant!
+<%= render :partial => 'users/abandon_form' %>
+<%= render :partial => 'users/sign_out_form' %>
diff --git a/config/routes.rb b/config/routes.rb
index 43a4a0e..eafbff7 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -5,13 +5,9 @@ AdoptAHydrant::Application.routes.draw do
:sessions => 'sessions',
}
resource :user
- get 'hydrants' => 'hydrants#index'
+ get 'hydrants' => 'hydrants#list'
resource :hydrant
- scope 'javascripts', :controller => 'javascripts', :as => 'javascripts' do
- get 'main', :action => 'main', :as => 'main'
- end
- get 'address' => 'addresses#index', :as => 'address'
+ get 'address' => 'addresses#show'
get 'sitemap' => 'sitemaps#index', :as => 'sitemap'
- get 'contents' => 'contents#index', :as => 'contents'
root :to => 'main#index'
end
diff --git a/app/views/javascripts/main.js.erb b/public/javascripts/application.js
similarity index 94%
rename from app/views/javascripts/main.js.erb
rename to public/javascripts/application.js
index e93b289..0b5110d 100644
--- a/app/views/javascripts/main.js.erb
+++ b/public/javascripts/application.js
@@ -38,7 +38,7 @@ $(function() {
if(activeInfoWindow) {
activeInfoWindow.close();
}
- $.get('<%= contents_path %>', {
+ $.get('/hydrant', {
'hydrant_id': hydrantId
}, function(data) {
var infoWindow = new google.maps.InfoWindow({
@@ -54,7 +54,7 @@ $(function() {
hydrantIds.push(hydrantId);
}
function addMarkersAround(lat, lng) {
- $.get('<%= hydrants_path :format => "json" %>', {
+ $.get('/hydrants.json', {
'commit': $('#address_submit').val(),
'utf8': '✓',
'authenticity_token': $('#address_form input[name="authenticity_token"]').val(),
@@ -111,7 +111,7 @@ $(function() {
$('#address').addClass('error', 500);
$('#address').focus();
} else {
- $.get('<%= address_path :format => "json" %>', {
+ $.get('/address.json', {
'commit': $('#address_submit').val(),
'utf8': '✓',
'authenticity_token': $('#address_form input[name="authenticity_token"]').val(),
@@ -184,7 +184,7 @@ $(function() {
if(errors.length > 0) {
errors[0].focus();
} else {
- $.post('<%= user_registration_path :format => "json" %>', {
+ $.post('/users.json', {
'commit': $('#user_sign_up_submit').val(),
'utf8': '✓',
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
@@ -231,7 +231,7 @@ $(function() {
}
errors[0].focus();
} else {
- $.get('<%= contents_path %>', {
+ $.get('/hydrant', {
'hydrant_id': activeHydrantId
}, function(data) {
activeInfoWindow.setContent(data);
@@ -251,7 +251,7 @@ $(function() {
if(errors.length > 0) {
errors[0].focus();
} else {
- $.post('<%= user_session_path :format => "json" %>', {
+ $.post('/users/sign_in.json', {
'commit': $('#user_sign_in_submit').val(),
'utf8': '✓',
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
@@ -266,7 +266,7 @@ $(function() {
$('#user_password').addClass('error', 500);
$('#user_password').focus();
} else {
- $.get('<%= contents_path %>', {
+ $.get('/hydrant', {
'hydrant_id': activeHydrantId
}, function(data) {
activeInfoWindow.setContent(data);
@@ -278,7 +278,7 @@ $(function() {
if(errors.length > 0) {
errors[0].focus();
} else {
- $.post('<%= user_password_path :format => "json" %>', {
+ $.post('/users/password.json', {
'commit': $('#user_forgot_password_submit').val(),
'utf8': '✓',
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
@@ -300,12 +300,12 @@ $(function() {
return false;
});
$('#sign_out_form').live('submit', function() {
- $.get('<%= destroy_user_session_path :format => "json" %>', {
+ $.get('/users/sign_out.json', {
'commit': $('#sign_out_form_submit').val(),
'utf8': '✓',
'authenticity_token': $('#sign_out_form input[name="authenticity_token"]').val()
}, function(data) {
- $.get('<%= contents_path %>', {
+ $.get('/hydrant', {
'hydrant_id': activeHydrantId
}, function(data) {
activeInfoWindow.setContent(data);
@@ -314,7 +314,7 @@ $(function() {
return false;
});
$('#adoption_form').live('submit', function() {
- $.post('<%= hydrant_path :format => "json" %>', {
+ $.post('/hydrant', {
'id': $('#hydrant_id').val(),
'commit': $('#adoption_form_submit').val(),
'utf8': '✓',
@@ -325,7 +325,7 @@ $(function() {
'name': $('#hydrant_name').val()
}
}, function(data) {
- $.get('<%= contents_path %>', {
+ $.get('/hydrant', {
'hydrant_id': activeHydrantId
}, function(data) {
activeInfoWindow.setContent(data);
@@ -343,7 +343,7 @@ $(function() {
$('#abandon_form').live('submit', function() {
var answer = window.confirm("Are you sure you want to abandon this hydrant?")
if(answer) {
- $.post('<%= hydrant_path :format => "json" %>', {
+ $.post('/hydrant', {
'id': $('#hydrant_id').val(),
'commit': $('#abandon_form_submit').val(),
'utf8': '✓',
@@ -354,7 +354,7 @@ $(function() {
'name': $('#hydrant_name').val()
}
}, function(data) {
- $.get('<%= contents_path %>', {
+ $.get('/hydrant', {
'hydrant_id': activeHydrantId
}, function(data) {
activeInfoWindow.setContent(data);
@@ -373,7 +373,7 @@ $(function() {
$('#steal_form').live('submit', function() {
var answer = window.confirm("Are you sure you want to steal this hydrant?")
if(answer) {
- $.post('<%= hydrant_path :format => "json" %>', {
+ $.post('/hydrant', {
'id': $('#hydrant_id').val(),
'commit': $('#steal_form_submit').val(),
'utf8': '✓',
@@ -384,7 +384,7 @@ $(function() {
'name': $('#hydrant_name').val()
}
}, function(data) {
- $.get('<%= contents_path %>', {
+ $.get('/hydrant', {
'hydrant_id': activeHydrantId
}, function(data) {
activeInfoWindow.setContent(data);