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 %> -<%= f.submit class: "btn blue" %>
- <% end %> +<%= f.submit class: "btn blue" %>
<% end %> \ No newline at end of file