From 5fcde6704084dad45a550aa4322bf50e2b80c763 Mon Sep 17 00:00:00 2001 From: jomo Date: Sun, 12 Oct 2014 21:54:32 +0200 Subject: [PATCH] improve blog comment replies --- app/models/blogpost.rb | 4 ++++ app/views/blogposts/show.html.erb | 12 +++++++++++- app/views/comments/_new.html.erb | 10 ++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/models/blogpost.rb b/app/models/blogpost.rb index a08a59a..9ff64fe 100644 --- a/app/models/blogpost.rb +++ b/app/models/blogpost.rb @@ -30,6 +30,10 @@ class Blogpost < ActiveRecord::Base title end + def can_comment? user + !user.nil? && user.confirmed? + end + def send_new_mention_mail(old_content = "") new_mentions = mentions(content) - mentions(old_content) mails = [] diff --git a/app/views/blogposts/show.html.erb b/app/views/blogposts/show.html.erb index 79a8c21..2bd4cf8 100644 --- a/app/views/blogposts/show.html.erb +++ b/app/views/blogposts/show.html.erb @@ -22,5 +22,15 @@ <%= render "comments/comment", c: c %> <% end %> <%= paginate @comments %> - <%= render "comments/new" %> + + + <% if current_user %> + <% if @post.can_comment? current_user %> + <%= render "comments/new" %> + <% else %> +

You don't have the required permission to reply here.

+ <% end %> + <% else %> +

Please <%= link_to "Log in", login_path(return_path: request.env['PATH_INFO']), action: "new" %> to post a reply.

+ <% end %> \ No newline at end of file diff --git a/app/views/comments/_new.html.erb b/app/views/comments/_new.html.erb index d6dd47b..8188c41 100644 --- a/app/views/comments/_new.html.erb +++ b/app/views/comments/_new.html.erb @@ -1,7 +1,5 @@ -<% if current_user %> -

New comment

- <%= form_for [@post, @comment] do |f| %> - <%= render partial: "md_editor", locals: {name: "comment[content]", content: @comment.content, mini: true} %> -

<%= f.submit class: "btn blue" %>

- <% end %> +

New comment

+<%= form_for [@post, @comment] do |f| %> + <%= render partial: "md_editor", locals: {name: "comment[content]", content: @comment.content, mini: true} %> +

<%= f.submit class: "btn blue" %>

<% end %> \ No newline at end of file