Create reminders in the database

This commit is contained in:
Erik Michaels-Ober 2011-06-13 15:39:39 -07:00
parent 463c528ce7
commit 43ff9fa78c
10 changed files with 77 additions and 5 deletions

View File

@ -746,4 +746,44 @@ $(function() {
});
return false;
});
$('#reminder_form').live('submit', function() {
var submitButton = $("#reminder_form input[type='submit']");
$(submitButton).attr("disabled", true);
$.ajax({
type: 'POST',
url: '/reminders.json',
data: {
'commit': submitButton.val(),
'utf8': '✓',
'authenticity_token': $('#sign_out_form input[name="authenticity_token"]').val(),
'reminder': {
'from_user_id': $('#reminder_from_user_id').val(),
'to_user_id': $('#reminder_to_user_id').val(),
'hydrant_id': activeHydrantId
}
},
beforeSend: function() {
$('#info_window').hide();
$('#loader').show();
},
error: function(jqXHR) {
$('#loader').hide();
$('#info_window').show();
$(submitButton).attr("disabled", false);
},
success: function(data) {
$.ajax({
type: 'GET',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId
},
success: function(data) {
activeInfoWindow.setContent(data);
}
});
}
});
return false;
});
});

View File

@ -0,0 +1,17 @@
class RemindersController < ApplicationController
respond_to :json
def create
puts params[:reminder].inspect
@reminder = Reminder.new(params[:reminder])
if @reminder.save
render(:json => @reminder)
else
render(:json => {"errors" => @reminder.errors}, :status => 500)
end
# ReminderMailer.send_reminder
# @reminder.sent = true
# @reminder.save!
end
end

View File

@ -0,0 +1,2 @@
module RemindersHelper
end

View File

@ -0,0 +1,2 @@
class ReminderMailer < ActionMailer::Base
end

View File

@ -0,0 +1,5 @@
= form_for :reminder, :url => reminders_path, :html => {:id => "reminder_form", :method => "post"} do |f|
= f.hidden_field "from_user_id", :value => current_user.id
= f.hidden_field "to_user_id", :value => @hydrant.user.id
= f.hidden_field "hydrant_id", :value => @hydrant.id
= f.submit "Send reminder to shovel"

View File

@ -4,8 +4,9 @@
%h3
= "of #{@hydrant.user.organization}"
- if user_signed_in?
= render :partial => 'users/edit_profile'
= render :partial => 'users/reminder'
= render :partial => 'hydrants/steal'
= render :partial => 'users/edit_profile'
= render :partial => 'sessions/sign_out'
- else
= render :partial => 'sessions/sign_in'

View File

@ -1,5 +1,5 @@
%h2
Thank you for adopting this hydrant!
= render :partial => 'users/edit_profile'
= render :partial => 'hydrants/abandon'
= render :partial => 'users/edit_profile'
= render :partial => 'sessions/sign_out'

View File

@ -8,5 +8,6 @@ AdoptAHydrant::Application.routes.draw do
get 'info_window' => 'info_window#index', :as => 'info_window'
get 'sitemap' => 'sitemaps#index', :as => 'sitemap'
resource :hydrants
resource :reminders
root :to => 'main#index'
end

View File

@ -5,10 +5,12 @@ class CreateReminders < ActiveRecord::Migration
t.integer :from_user_id, :null => false
t.integer :to_user_id, :null => false
t.integer :hydrant_id, :null => false
t.boolean :sent, :default => false
end
add_index :reminders, :from_user_id
add_index :reminders, :to_user_id
add_index :reminders, :hydrant_id
add_index :reminders, :sent
end
end

View File

@ -27,13 +27,15 @@ ActiveRecord::Schema.define(:version => 3) do
create_table "reminders", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.integer "from_user_id", :null => false
t.integer "to_user_id", :null => false
t.integer "hydrant_id", :null => false
t.integer "from_user_id", :null => false
t.integer "to_user_id", :null => false
t.integer "hydrant_id", :null => false
t.boolean "sent", :default => false
end
add_index "reminders", ["from_user_id"], :name => "index_reminders_on_from_user_id"
add_index "reminders", ["hydrant_id"], :name => "index_reminders_on_hydrant_id"
add_index "reminders", ["sent"], :name => "index_reminders_on_sent"
add_index "reminders", ["to_user_id"], :name => "index_reminders_on_to_user_id"
create_table "users", :force => true do |t|