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
27 changes: 26 additions & 1 deletion app/controllers/answers.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
post '/questions/:question_id/answers' do
@question = Question.find_by(id: params[:question_id])
@answer = Answer.new(description: params[:description])
@answer = Answer.new(description: params[:description], user_id: current_user.id)
@answers = @question.answers
@comments = @answer.comments
if @answer.save
Expand All @@ -27,3 +27,28 @@
redirect "/questions/#{@question.id}"
end
end

# post '/questions/:question_id/answers/:answer_id/answer/upvote' do
# @question = Question.find_by(id: params[:question_id])
# @answer = Answer.find_by(id: params[:answer_id])
# binding.pry
# @answer.votes.create(value: 1)

# if request.xhr?
# {points: @answer.points}.to_json
# else
# redirect "/questions/#{@question.id}"
# end
# end

# post '/questions/:question_id/downvote' do
# @question = Question.find_by(id: params[:question_id])
# @answer = Answer.find_by(id: params[:answer_id])
# @answer.votes.create(value: -1)

# if request.xhr?
# {points: @answer.points}.to_json
# else
# redirect "/questions/#{@question.id}"
# end
# end
Empty file.
Empty file.
File renamed without changes.
43 changes: 28 additions & 15 deletions app/views/questions/show.erb
Original file line number Diff line number Diff line change
@@ -1,37 +1,54 @@
<div class= "container">
<div class="question-title">
<h1><%=@question.title%><span class="vote-button"><%= erb :_vote_button %></span></h1>
<h1><%=@question.title%><span class="vote-button"><%= erb :_question_vote_button %></span></h1>
</div>

<p class="question-description"><%=@question.description%></p>

<ul id ="question-comment-list">
<% @question.comments.each do |comment| %>
<div class = "question">
<%= erb :'/comments/_individual_comment', locals: {answer: @answer, question: @question, comment: comment} %>
<% end %>
</ul>
<div class="comments-container">
<h4 class="orange-underline">Comments</h4>

<a class= 'add-question-comment-link' href= "#" >Add a comment to this question</a><br>
<a class='add-question-comment-link' href= "#" ><h4 class="white">Add a comment</a></h4>

<form action = "/questions/<%=@question.id%>/question_comment" method = "POST" class= "question-comment-form hidden">
<input id = "#question-comment-description" type ="text" name= "description" placeholder= "Your Comment">
<input type ="submit" value= "Submit Comment">
</form>

</div>

<ul id ="question-comment-list">
<% @question.comments.each do |comment| %>
<div class = "question">
<%= erb :'/comments/_individual_comment', locals: {answer: @answer, question: @question, comment: comment} %>
<% end %>
</ul>

<form action = "/questions/<%=@question.id%>/question_comment" method = "POST" class= "comment-form hidden">
<input type ="text" name= "description" placeholder= "Your Comment">
<input type ="submit" value= "Submit Comment">
</form>

</div>

<div class="answer-container">
<h1 class="orange-underline">Answers</h1>

<ul id= "answer-list">

<h3><a id= "add-answer-button" href= "#">Add an Answer</a></h3>

<form id= "answer-form" action = "/questions/<%=@question.id%>/answers" method = "POST" class= "hidden">
<input type ="text" name= "description" placeholder= "Your Answer">
<input type ="submit" value= "Submit Answer">
</form>

<% @answers.each do |answer| %>
<div class = "answer" id = "<%=answer.id%>">
<%= erb :'/answers/_individual_answer', locals: {answer: answer, question: @question} %>
<span class="vote-button"><%= erb :_answer_vote_button %></span>

<div class="comments-container">

<ul class ="answer-comment-list">
<% answer.comments.each do |comment| %>
<%= erb :'/comments/_individual_comment', locals: {answer: answer, question: @question, comment: comment} %>
Expand All @@ -40,13 +57,9 @@
<% end %>
</div>
</ul>
</div>

<h3><a id= "add-answer-button" href= "#">Add an Answer</a></h3>

<form id= "answer-form" action = "/questions/<%=@question.id%>/answers" method = "POST" class= "hidden">
<input type ="text" name= "description" placeholder= "Your Answer">
<input type ="submit" value= "Submit Answer">
</form>

</div>

</div>
60 changes: 51 additions & 9 deletions public/css/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ body {
.container {
margin-top: 12em;
text-align: center;
padding-bottom: 5em;
padding-bottom: 15em;
}

#question-form {
Expand All @@ -31,6 +31,7 @@ body {
display: inline;
margin-top: 0;
}

.vote-button {
font-size: 12px;
display: inline-block;
Expand All @@ -42,6 +43,52 @@ body {
margin-right: auto;
}




/* Question Show Page */

.orange-underline {
border-bottom: 5px solid;
border-color: #D86E3E;
color: #3A5863;
}

.answer-container {
margin-left: auto;
margin-right: auto;
margin-top: 3em;
width: 40em;
color: #3A5863;
line-height: 2em;
}

.answer-container ul {
list-style-type: none;
padding: 0;
}
.add-question-comment-link a {
color: #3A5863;
}

.add-question-comment-link a:hover {
color: #D86E3E;
}

.comments-container {
margin-left: auto;
margin-right: auto;
margin-top: 3em;
width: 20em;
color: #3A5863;
line-height: 2em;
}

.comments-container ul {
list-style-type: none;
padding: 0;
}

.question-table td {
padding: 2em;
background-color: #3A5863;
Expand Down Expand Up @@ -71,15 +118,10 @@ body {
.question-description {
margin-left: auto;
margin-right: auto;
width: 55em;
padding-right: 5em;
padding-left: 5em;
}

.question-description p {
font-size: 120%;
color: #3A5863;
width: 40em;
word-wrap: break-word;
color: #3A5863;
font-size: 120%;
}


Expand Down
2 changes: 2 additions & 0 deletions public/css/normalize.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ template {
a {
background: transparent;
text-decoration: none;
color: #3A5863;
}

/**
Expand All @@ -94,6 +95,7 @@ a {
a:active,
a:hover {
outline: 0;
color: #D86E3E;
}

/* Text-level semantics
Expand Down
4 changes: 4 additions & 0 deletions public/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ $(document).ready(function() {
$(".total-points").text(voteObject.points);
})
});




$('#ask-a-question-button').on("click", "a", function(e){
e.preventDefault();
$('#question-form').show();
Expand Down