Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//= require jquery_ujs
//= require_tree .

// Code does not go here, if it does nothing remove it.
$('document').ready(function(){
$('#comment_for_answer').on('submit', function(event){
event.preventDefault();
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/comments.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Remove it if it doesn't do anything
// $('document').ready(function(){
// $('.comment_for_answer').on("submit", function(event) {
// event.preventDefault();
Expand Down
2 changes: 2 additions & 0 deletions app/assets/javascripts/votes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Nice work
$(document).ready(function () {
$('.questionvote').on('submit', function(event){
event.preventDefault();
var $data = $(event.target).serialize();
var $voteCount = $(event.target).closest('.questionvote').find('#questionvotecount');
$.ajax({
// Url should probably be POST /votes
url: '/questionvotes',
method: 'POST',
data: $data
Expand Down
1 change: 1 addition & 0 deletions app/controllers/answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ def create
user = User.find_by(id: session[:user_id])
@answer = Answer.create(answer_params)
@answer.update_attributes(user_id: user.id)
# Didnt you store param[:answer] in answer_params (see 2 lines up)
question = Question.find_by(id: params[:answer][:question_id])
redirect_to question_path(question.id)
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def new
@answer_id = params["answer_id"]
end

# See Wed. night lecture comments. We can clean this up by extracting
# private methods to help clean things up.
def create
@comment = Comment.new(comment_params)
if comment_params[:commentable_type] == "question"
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/votes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class VotesController < ApplicationController
# Seems like we could clean this up a good bit. Nevertheless, I like your
# creation of helper methods such as the misspelled
# user_previosly_voted_differently, etc.
def questionvotes
question = Question.find_by(id: params[:question_id])
if user_has_made_this_vote(question, params[:question_id])
Expand Down Expand Up @@ -50,6 +53,8 @@ def answervotes

def user_has_made_this_vote(questionoranswer, upvote)
vote = questionoranswer.votes.find_by(user_id: current_user.id)
# The return value of vote && (vote.upvote? == upvote) is true false, you
# don't need to explicitly return it.
return true if vote && vote.upvote? == upvote
end

Expand Down
1 change: 1 addition & 0 deletions db/migrate/20150708234013_create_tags.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class CreateTags < ActiveRecord::Migration
def change
create_table :tags do |t|
# That's probably not nullable...
t.string :name

t.timestamps null: false
Expand Down
1 change: 0 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
add_index "votes", ["user_id"], name: "index_votes_on_user_id", using: :btree
add_index "votes", ["votable_type", "votable_id"], name: "index_votes_on_votable_type_and_votable_id", using: :btree

add_foreign_key "answers", "users"
add_foreign_key "comments", "users"
add_foreign_key "favorite_questions", "questions"
add_foreign_key "favorite_questions", "users"
Expand Down
2,786 changes: 2,786 additions & 0 deletions log/development.log

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions spec/factories/comments.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Ross: Your indentation is insane
FactoryGirl.define do
factory :comment do
body "MyString"
Expand Down
3 changes: 3 additions & 0 deletions spec/models/comment_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require 'rails_helper'

# Hm, who was using model generators.......
#
# don't commit crap like these
RSpec.describe Comment, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
6 changes: 6 additions & 0 deletions steven_notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* Testing: I would have expected some
* Controllers looked nice, but you have a few really complex methods: see tips
on simplifying things from Wed nite
* JavaScript was good eventy stuff for small improvements to a Rails site
* Models looked good; nice use of advanced association magic