-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added automated email notifications for people providing answers. Add…
…ed development gems: gem to auto-populate data and gem to handle server loads on email requests. Added security layer on development login to protect user data.
- Loading branch information
Showing
31 changed files
with
285 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Place all the behaviors and hooks related to the matching controller here. | ||
// All this logic will automatically be available in application.js. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
@import "bootstrap"; | ||
@import "bootstrap"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the favourites controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class FavouritesController < ApplicationController | ||
|
||
before_action :authenticate_user! | ||
before_action :find_question | ||
|
||
def create | ||
@question = Question.find(params[:question_id]) | ||
@favourite = @question.favourites.new | ||
@favourite.user = current_user | ||
if @favourite.save | ||
redirect_to @question, notice: "Thank you for favouriting!" | ||
else | ||
redirect_to @question, alert: "Could not favourite again!" | ||
end | ||
|
||
end | ||
|
||
def destroy | ||
@favourite = current_user.favourites.find(params[:id]) | ||
if @favourite.destroy | ||
redirect_to @question, alert: "You have unfavourited!" | ||
else | ||
redirect_to @question, alert: "Could not unfavourite!" | ||
end | ||
end | ||
|
||
private | ||
|
||
def find_question | ||
@question = Question.find(params[:question_id]) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module FavouritesHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class AnswerMailer < ActionMailer::Base | ||
default from: "[email protected]" | ||
|
||
def notify_question_owner(answer) | ||
@answer = answer | ||
@question = answer.question | ||
@receiver = @question.user | ||
mail(to: @receiver.email, | ||
subject: "You have a new answer on your question!") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Favourite < ActiveRecord::Base | ||
belongs_to :question | ||
belongs_to :user | ||
|
||
validates :user_id, uniqueness: {scope: :question_id} | ||
#prevents users from favouriting any single question more than once | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Hello #{@receiver.full_name}, | ||
|
||
You have an answer for your question: | ||
|
||
Question: #{@question.title} | ||
|
||
Answer: #{@answer.body} | ||
|
||
Regards, | ||
|
||
Customer Service Team |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
%p Hello #{@receiver.full_name}, | ||
%br | ||
%p You have an answer for your question: | ||
%br | ||
%p Question: #{@question.title} | ||
%br | ||
%p Answer: #{@answer.body} | ||
%br | ||
%p Regards, | ||
%br | ||
%p Customer Service Team |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment')) | ||
require 'delayed/command' | ||
Delayed::Command.new(ARGV).daemonize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
ActionMailer::Base.smtp_settings = { | ||
address: 'smtp.gmail.com', | ||
port: '587', | ||
enable_starttls_auto: true, | ||
user_name: ENV['email_username'], | ||
password: ENV['email_password'], | ||
authentication: :plain | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateFavourites < ActiveRecord::Migration | ||
def change | ||
create_table :favourites do |t| | ||
t.references :question, index: true | ||
t.references :user, index: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class CreateDelayedJobs < ActiveRecord::Migration | ||
def self.up | ||
create_table :delayed_jobs, :force => true do |table| | ||
table.integer :priority, :default => 0, :null => false # Allows some jobs to jump to the front of the queue | ||
table.integer :attempts, :default => 0, :null => false # Provides for retries, but still fail eventually. | ||
table.text :handler, :null => false # YAML-encoded string of the object that will do work | ||
table.text :last_error # reason for last failure (See Note below) | ||
table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future. | ||
table.datetime :locked_at # Set when a client is working on this object | ||
table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead) | ||
table.string :locked_by # Who is working on this object (if locked) | ||
table.string :queue # The name of the queue this job is in | ||
table.timestamps | ||
end | ||
|
||
add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority' | ||
end | ||
|
||
def self.down | ||
drop_table :delayed_jobs | ||
end | ||
end |
Oops, something went wrong.