diff --git a/app/controllers/answers.rb b/app/controllers/answers.rb index d880504..0737fa1 100644 --- a/app/controllers/answers.rb +++ b/app/controllers/answers.rb @@ -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 diff --git a/app/views/_vote_button.erb b/app/views/_question_vote_button.erb similarity index 100% rename from app/views/_vote_button.erb rename to app/views/_question_vote_button.erb diff --git a/app/views/answers/_individual_answer.erb b/app/views/answers/_individual_answer.erb index 1b4ce31..f608948 100644 --- a/app/views/answers/_individual_answer.erb +++ b/app/views/answers/_individual_answer.erb @@ -1,9 +1,19 @@ -
  • - <%=answer.description%>
  • +
    +
  • <%=answer.description%>
  • +<% if logged_in? %> Add a comment to this answer
    +<% end %> + + +
    + diff --git a/app/views/index.erb b/app/views/index.erb deleted file mode 100644 index e69de29..0000000 diff --git a/app/views/layout.erb b/app/views/layout.erb index d3d5a67..dce5a79 100644 --- a/app/views/layout.erb +++ b/app/views/layout.erb @@ -32,7 +32,9 @@
    + <% if logged_in? %>

    Ask a Question

    + <% end %>

    Questions

    diff --git a/app/views/questions/_individual_question.erb b/app/views/questions/_individual_question.erb index 569c953..4eff771 100644 --- a/app/views/questions/_individual_question.erb +++ b/app/views/questions/_individual_question.erb @@ -1,4 +1,3 @@ <%=question.title%> - diff --git a/app/views/questions/index.erb b/app/views/questions/index.erb index 33fcde1..5ca1e83 100644 --- a/app/views/questions/index.erb +++ b/app/views/questions/index.erb @@ -1,5 +1,8 @@
    -

    Questions

    + +
    +

    Questions

    +

    <%= erb :'/_errors', layout: false %>

    +
    +

    Answers

    + <% if logged_in? %>

    Add an Answer

    + <% end %> + <% @answers.each do |answer| %> +
    + <%= erb :'/answers/_individual_answer', locals: {answer: answer, question: @question} %> + <% end %> +
    + +
    diff --git a/app/views/sessions/login.erb b/app/views/sessions/login.erb index 10e0f5b..55a3b4e 100644 --- a/app/views/sessions/login.erb +++ b/app/views/sessions/login.erb @@ -1,5 +1,10 @@
    -

    Login to TravelOverflow

    + +
    +
    +

    Login to Travel Overflow!

    +
    +
    <% if @errors %> <% @errors.each do |error| %> @@ -7,14 +12,18 @@ <% end %> <% end %> +
    +
    - - - +
    +
    +
    -

    Not registered? Sign up now!

    - +
    +
    +

    Not registered? Sign up now!

    +
    diff --git a/app/views/users/new.erb b/app/views/users/new.erb index 2dbd0fe..e0ed7ef 100644 --- a/app/views/users/new.erb +++ b/app/views/users/new.erb @@ -1,5 +1,10 @@
    -

    Register for TravelOverflow!

    + +
    +
    +

    Register for Travel Overflow!

    +
    +
    <% if @errors %> <% errors.each do |error| %> @@ -7,9 +12,18 @@ <% end %> <% end %> +
    +
    - - - +
    +
    +
    + +
    + +
    +

    Already registered? Login in!

    +
    +
    diff --git a/app/views/users/show.erb b/app/views/users/show.erb index 3f107aa..f904937 100644 --- a/app/views/users/show.erb +++ b/app/views/users/show.erb @@ -1,39 +1,62 @@
    -

    Welcome, <%= @user.username.capitalize %>!

    +

    Welcome, <%= @user.username.capitalize %>!

    -

    Questions

    +
    +

    Your Questions

    + <% @user_questions.each do |question| %> -

    <%= question.title %>

    + + <% end %> + +
    <%= question.title %>
    +
    -

    Answers

    +
    +

    Your Answers

    + <% @user_answers.each do |answer| %> + <% @question_answered %> -

    <%=@question_answered.title%> <%= answer.description %>

    + <% end %> + +
    Question: <%=@question_answered.title%>
    Answer: <%= answer.description %>
    +
    -

    Comments on Questions

    +
    +

    Comments on Questions

    + <% @user_comments.each do |comment| %> <% if comment.commentable_type == "Question" %> <% @commented_question_id = comment.commentable_id %> <% @question_commented_on = Question.find_by(id: @commented_question_id)%> - <%= @question_commented_on.title %> - <%= comment.description %> + + <% end %> <% end %> + +
    Question: <%= @question_commented_on.title %>
    + Comment: <%= comment.description %>
    +
    -

    Comments on Answers

    +
    +

    Comments on Answers

    + <% @user_comments.each do |comment| %> <% if comment.commentable_type == "Answer" %> <% @commented_answer_id = comment.commentable_id %> <% @answer_commented_on = Answer.find_by(id: @commented_answer_id)%> <% @question_of_commented_answer = Question.find_by(id: @answer_commented_on.question_id) %> - -

    Question: <%=@question_of_commented_answer.title%>

    -

    Answer:<%= @answer_commented_on.description %>

    -

    Comment:<%= comment.description %>

    - <% end %> + + <% end %> + +
    Question: <%=@question_of_commented_answer.title%>
    + Answer: <%= @answer_commented_on.description %>
    + Comment: <%= comment.description %> + <% end %>
    +
    diff --git a/public/css/application.css b/public/css/application.css index f50e465..ddf8b85 100644 --- a/public/css/application.css +++ b/public/css/application.css @@ -1,88 +1,14 @@ body { background-color: #E7E7E7; } + .container { margin-top: 12em; text-align: center; - padding-bottom: 5em; -} - -#question-form { - background-color: #3A5863; - width: 44em; - height: 22em; - margin-left: auto; - margin-right: auto; -} - -.white { - color: white; + padding-bottom: 15em; } -.title-box { - height: 2em; - width: 30em; -} - -.description-box { - height: 8em; - width: 30em; - word-wrap: break-word; - display: inline; - margin-top: 0; -} -.vote-button { - font-size: 12px; - display: inline-block; - float: right; -} - -.question-table { - margin-left: auto; - margin-right: auto; -} - -.question-table td { - padding: 2em; - background-color: #3A5863; - border: .5em solid; - border-color: #E7E7E7; - width: 40em; -} - -.question-table a { - color: white; -} - -.question-table a:hover { - color: #D86E3E; -} - -.question-title { - width: 55em; - margin-left: auto; - margin-right: auto; - border-bottom: 5px solid; - border-color: #D86E3E; - color: #3A5863; - margin-bottom: 0; -} - -.question-description { - margin-left: auto; - margin-right: auto; - width: 55em; - padding-right: 5em; - padding-left: 5em; -} - -.question-description p { - font-size: 120%; - color: #3A5863; - word-wrap: break-word; -} - - +/* Header/Footer */ #top-header { background-color: #3A5863; height: 2em; @@ -208,3 +134,166 @@ body { display: none; } + + +/* Ask a Question Section */ +#question-form { + background-color: #3A5863; + width: 44em; + height: 22em; + margin-left: auto; + margin-right: auto; +} + +.vote-button { + font-size: 12px; + display: inline-block; + float: right; +} + +.question-table { + margin-left: auto; + 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; + border: .5em solid; + border-color: #E7E7E7; + width: 40em; +} + +.question-table a { + color: white; +} + +.question-table a:hover { + color: #D86E3E; +} + +.question-title { + width: 55em; + margin-left: auto; + margin-right: auto; + border-bottom: 5px solid; + border-color: #D86E3E; + color: #3A5863; + margin-bottom: 0; +} + +.question-description { + margin-left: auto; + margin-right: auto; + width: 40em; + word-wrap: break-word; + color: #3A5863; + font-size: 120%; +} + + + + + +/* User Show Page */ + +.profile-container { + margin-left: auto; + margin-right: auto; + margin-top: 3em; + width: 40em; + color: white; + line-height: 2em; +} + +/* Change Font Colors */ + +.blue { + color: #3A5863; +} + +.orange { + color: #D86E3E; +} + +.white { + color: white; +} + +/* Sign Up/Login */ +.sign-form-container { + margin-left: auto; + margin-right: auto; + margin-top: 3em; + width: 35em; + line-height: 4.5em; + background-color: #3A5863; + padding: 1em; +} + +/* Form input size changes */ +.title-box { + height: 2em; + width: 30em; +} + +.description-box { + height: 8em; + width: 30em; + word-wrap: break-word; + display: inline; + margin-top: 0; +} + +.register-button { + background-color: #D86E3E; + border:none; + font-size: 150%; + padding: .5em; + color: white; +} diff --git a/public/css/normalize.css b/public/css/normalize.css index 15f23c5..86bc385 100644 --- a/public/css/normalize.css +++ b/public/css/normalize.css @@ -85,6 +85,7 @@ template { a { background: transparent; text-decoration: none; + color: #3A5863; } /** @@ -94,8 +95,19 @@ a { a:active, a:hover { outline: 0; + color: #D86E3E; } +/* BULLET POINTS ========================================================================== */ +ul { + list-style-type: none; + padding: 0; +} + +li { + list-style-type: none; + padding: 0; +} /* Text-level semantics ========================================================================== */ diff --git a/public/js/application.js b/public/js/application.js index 341bd02..81fde4e 100644 --- a/public/js/application.js +++ b/public/js/application.js @@ -27,10 +27,7 @@ $(document).ready(function() { data: data }); ajaxRequest.done(function(response){ - $('.title-box').val(''); - $('.description-box').val(''); - $('#question-form').hide(); - $('.question-table').prepend(response); + $('#question-list').append(response); }); }); $('#add-answer-button').on("click", function(e){ @@ -54,12 +51,10 @@ $(document).ready(function() { $('#answer-list').append(response); }); }); - $('.answer a').on("click", function(e){ + $('.add-answer-comment-link').on("click", function(e){ e.preventDefault(); - $('.answer-comment-form').hide(); $(this).hide() - $('#' + e.target.parentElement.id + ' form').show(); - $('.answer a').show(); + $('#' + this.parentElement.id + ' form').show(); $('#' + e.target.parentElement.id + ' form').on("submit", function(e){ e.preventDefault(); var data = $(e.target).serialize(); @@ -70,12 +65,7 @@ $(document).ready(function() { type: type, data: data }).done(function(response){ - if (e.target.parentElement.id == 1) { - $('ul.answer-comment-list').eq(0).append(response); - } - else{ - $('#' + e.target.parentElement.id + ' ul.answer-comment-list').append(response); - }; + $('#' + e.target.parentElement.id).children('ul').append(response); $('#' + e.target.parentElement.id + ' form').children('#answer-comment-description').val(''); }); }); @@ -101,5 +91,3 @@ $(document).ready(function() { }); }); }); - -