Commit a5a23863 authored by simon's avatar simon
Browse files

Add remote: true to upvote links and forms

parent fb13c03a
......@@ -368,7 +368,7 @@ section.container {
img {
width: 75%;
margin: auto;
&.selected{
&.selected {
width: 75%;
background-color: $highlight;
border-radius: 100%;
......@@ -424,11 +424,10 @@ section.container {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
h2{
h2 {
display: block;
padding: 1rem;
}
ul {
list-style: none;
......@@ -505,11 +504,11 @@ section.container {
}
img {
width: 2rem;
&.selected{
&.selected {
background-color: $highlight;
border-radius: 100%;
padding: -2px;
}
}
}
}
}
......@@ -521,7 +520,3 @@ section.container {
// Update Post //
// //
////////////////////////////
......@@ -4,7 +4,6 @@
class PostsController < ApplicationController
before_action :set_post, only: %w[show edit update destroy like dislike]
before_action :initialize_all_tags, only: %w[index create update]
# before_action :authenticate_user!
# GET /posts
# GET /posts.json
......@@ -16,7 +15,7 @@ class PostsController < ApplicationController
# GET /posts/1.json
def show
@comments = @post.comments
@comment = Comment.new(post_id: @post.id)
@comment = Comment.new
end
# GET /posts/new
......@@ -47,7 +46,8 @@ class PostsController < ApplicationController
# PATCH/PUT /posts/1
# PATCH/PUT /posts/1.json
def update # TODO Refactor
# TODO: Refactor
def update
if @post.content_image.attached?
@post.content_image.attach(post_params[:content_image]) unless post_params[:content_image].nil?
respond_to do |format|
......
<% if comment.errors.any? %>
<div id="error_explanation"> <%# TODO Style div for errors %>
<h2><%= pluralize(comments.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% comment.errors.full_messages.each do |message| %>
<li>
<%= message %>
</li>
<% end %>
</ul>
</div>
<% end %>
<%= form_for(comment, url: comments_path, method: "post") do |form| %>
<%= form_with(model: comment, url: comments_path, method: "post") do |form| %>
<div class="field">
<%= form.text_area :content %>
</div>
......
<% @comments.each do |comment| %>
<% comments.each do |comment| %>
<div class="single-comment">
<div class="comment-top">
<span><%= comment.user.username %></span>
......
......@@ -8,7 +8,7 @@
<%= render 'messages' %>
</div>
</div>
<%= form_for @conversation_message, html: {class: 'message-form'} do |f| %>
<%= form_with(model: @conversation_message, html: {class: 'message-form'}) do |f| %>
<%= hidden_field_tag 'conversation_id', @conversation.id %>
<%= f.text_area :content, placeholder: "" %>
<%= f.submit "SEND" %>
......
<% comments.each do |comment| %>
<div class="single-comment">
<div class="comment-top">
<span><%= comment.user.username %></span>
<span><%= utc_to_readable(comment.created_at) %></span>
</div>
<div class="comment-content">
<span><%= comment.content %></span>
</div>
</div>
<% end %>
......@@ -29,9 +29,9 @@
<button class="submit"><%= link_to "read more", post, :class => "no-link-styles" %></button>
</div>
<div class="upvotes">
<%= link_to image_tag("arrow-circle-up-solid.svg", class: "#{'selected' if current_user.liked? post}"), like_post_path(post), method: :put %>
<%= link_to image_tag("arrow-circle-up-solid.svg", class: "#{'selected' if current_user.liked? post}"), like_post_path(post), remote: true, method: :put %>
<h2><%= post.weighted_score %></h2>
<%= link_to image_tag("arrow-circle-down-solid.svg", class: "#{'selected' if current_user.disliked? post}"), dislike_post_path(post), method: :put %>
<%= link_to image_tag("arrow-circle-down-solid.svg", class: "#{'selected' if current_user.disliked? post}"), dislike_post_path(post), remote: true, method: :put %>
</div>
</div>
</div>
......
<div class="show-container">
<div class="show-content">
<div class="heading">
<% if @post.user == current_user %>
<%= link_to image_tag("edit-solid.svg", :class => "edit"), edit_post_path %>
<% end %>
<h2><%= @post.title %></h2>
<div class="show-content">
<div class="heading">
<% if @post.user == current_user %>
<%= link_to image_tag("edit-solid.svg", :class => "edit"), edit_post_path %>
<% end %>
<h2><%= @post.title %></h2>
</div>
<div class="tags">
<ul>
<li class="tag-small">backend</li>
<li class="tag-small">ruby</li>
<li class="tag-small">rails</li>
</ul>
</div>
<div class="description">
<%= markdown_to_html(@post.content_text).html_safe %>
</div>
<div class="image">
<% if @post.content_image.attached? %>
<% @post.content_image.each do |image| %>
<%= image_tag(image.variant(resize_to_limit: [500, 500]), :tabindex => -1) %>
<% end %>
<% else %>
<h2>Nothing to see here</h2>
<% end %>
</div>
</div>
<div class="tags">
<ul>
<li class="tag-small">backend</li>
<li class="tag-small">ruby</li>
<li class="tag-small">rails</li>
</ul>
<div class="show-comments">
<div class="comments-wrapper-inverse">
<div class="comments-wrapper">
<%= render partial: "comments/comment", locals: {comments: @comments} %>
</div>
</div>
<%= render partial: "comments/comment-form", locals: {comment: @comment, post: @post} %>
</div>
<div class="description">
<%= markdown_to_html(@post.content_text).html_safe %>
<div class="upvotes">
<div class="user">
<p>posted by:</p>
<h3>
<%= @post.user.username %>
</h3>
</div>
<div class="votes">
<div>
<%= link_to image_tag("arrow-circle-up-solid.svg", class: "#{'selected' if current_user.liked? @post}"), like_post_path, remote: true, method: :put %>
<h2><%= @post.weighted_score %></h2>
<%= link_to image_tag("arrow-circle-down-solid.svg", class: "#{'selected' if current_user.disliked? @post}"), dislike_post_path, remote: true, method: :put %>
</div>
</div>
</div>
<div class="image">
<% if @post.content_image.attached? %>
<% @post.content_image.each do |image| %>
<%= image_tag(image.variant(resize_to_limit: [500, 500]), :tabindex => -1) %>
<% end %>
<% else %>
<h2>Nothing to see here</h2>
<% end %>
</div>
</div>
<div class="show-comments">
<div class="comments-wrapper-inverse">
<div class="comments-wrapper">
<%= render @comments %>
</div>
</div>
<%= render partial: "comments/comment-form", locals: {comment: @comment, post: @post} %>
</div>
<div class="upvotes">
<div class="user">
<p>posted by:</p>
<h3>
<%= @post.user.username %>
</h3>
</div>
<div class="votes">
<div>
<%= link_to image_tag("arrow-circle-up-solid.svg", class: "#{'selected' if current_user.liked? @post}"), like_post_path, method: :put %>
<h2><%= @post.weighted_score %></h2>
<%= link_to image_tag("arrow-circle-down-solid.svg", class: "#{'selected' if current_user.disliked? @post}"), dislike_post_path, method: :put %>
</div>
</div>
</div>
</div>
</div>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment