comments
This commit is contained in:
parent
c99b993fb5
commit
27d7568a83
@ -106,3 +106,45 @@ article{
|
||||
font-size:1em;
|
||||
|
||||
}
|
||||
|
||||
.comment{
|
||||
.header{
|
||||
margin-top:0;
|
||||
font-size:14px;
|
||||
font-family:"jaf-bernino-sans", sans-serif;
|
||||
}
|
||||
aside{
|
||||
float:left;
|
||||
img{
|
||||
width:50px;
|
||||
height:50px;
|
||||
border-radius:50%;
|
||||
}
|
||||
}
|
||||
.comment_body{
|
||||
margin-left:60px;
|
||||
background:rgba(250,250,250,1);
|
||||
padding:20px;
|
||||
margin-bottom:20px;
|
||||
}
|
||||
blockquote{
|
||||
margin:0;
|
||||
margin-top:1em;
|
||||
padding:0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.child_comments{
|
||||
padding-left:60px;
|
||||
|
||||
}
|
||||
|
||||
.comment_form{
|
||||
padding:10px;
|
||||
background: rgba(250,250,250,1);
|
||||
margin-bottom:20px;
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,16 @@
|
||||
class Public::CommentsController < ApplicationController
|
||||
|
||||
def new
|
||||
@comment = Comment.new(:parent_id => params[:parent_id],:commentable_id => params[:commentable_id],:commentable_type => params[:commentable_type])
|
||||
|
||||
end
|
||||
|
||||
def create
|
||||
@comment = Comment.new(params.require(:comment).permit(:website, :pseudo, :email, :comment, :commentable_id, :commentable_type))
|
||||
@comment = Comment.new(params.require(:comment).permit(:website, :pseudo, :email, :comment, :commentable_id, :commentable_type, :parent_id))
|
||||
|
||||
|
||||
|
||||
|
||||
@comment.enabled = true
|
||||
if @comment.save
|
||||
commentable = @comment.commentable
|
||||
@comment_id = @comment.id
|
||||
|
@ -10,6 +10,7 @@ class Comment < ActiveRecord::Base
|
||||
|
||||
scope :recents, -> {where("enabled = ?",true ).order("created_at ASC")}
|
||||
|
||||
acts_as_tree
|
||||
|
||||
|
||||
|
||||
|
@ -11,10 +11,10 @@
|
||||
|
||||
#comments
|
||||
%h2 Commentaires
|
||||
=render :partial => "public/comments/comment", :collection => @article.comments.recents
|
||||
=render :partial => "public/comments/comment", :collection => @article.comments.where(:enabled => true, :parent_id => nil).order("created_at DESC")
|
||||
|
||||
#comment_form.background_opacity.padding_20
|
||||
=render :partial => "public/comments/form"
|
||||
|
||||
=render :partial => "public/comments/form"
|
||||
|
||||
|
||||
|
||||
|
@ -1,26 +1,29 @@
|
||||
.comment#comment{:class => ("author" if comment.email == "info@nicolasbally.com"), :id => comment.id}
|
||||
%aside=gravatar_image_tag(comment.email? ? comment.email : comment.pseudo, :gravatar => {:default => "http://#{HOSTNAME}/default_avatar.jpg"})
|
||||
|
||||
|
||||
%p.header
|
||||
|
||||
Commentaire de
|
||||
%strong
|
||||
|
||||
-if comment.website?
|
||||
=link_to comment.pseudo, comment.website, :target => "_blank"
|
||||
-else
|
||||
=comment.pseudo
|
||||
|
||||
%time.updated{:datetime => Time.now, :pubdate => true}
|
||||
envoyé
|
||||
="le "+l(comment.created_at, :format => :human_date)
|
||||
|
||||
|
||||
|
||||
%aside=gravatar_image_tag(comment.email? ? comment.email : comment.pseudo, :gravatar => {:default => "http://#{HOSTNAME}/default_avatar.jpg"})
|
||||
|
||||
|
||||
.comment_body
|
||||
%div.header
|
||||
.right.coms
|
||||
=link_to ic(:share), new_public_comment_path(:commentable_id => comment.commentable_id, :commentable_type =>comment.commentable_type, :parent_id => comment.id), :remote => true, :class => "add_comment"
|
||||
%strong
|
||||
|
||||
-if comment.website?
|
||||
=link_to(comment.pseudo, comment.website, :target => "_blank")+","
|
||||
-else
|
||||
=comment.pseudo+","
|
||||
|
||||
|
||||
%time.updated{:datetime => Time.now, :pubdate => true}
|
||||
="le "+l(comment.created_at, :format => :human_date)
|
||||
|
||||
|
||||
|
||||
|
||||
%blockquote=simple_format comment.comment
|
||||
|
||||
.child_comments
|
||||
=render comment.children.where(:enabled => true).order(:created_at)
|
||||
|
||||
|
||||
%blockquote=simple_format comment.comment
|
||||
|
||||
|
||||
|
||||
|
@ -1,32 +1,33 @@
|
||||
#comment_form.comment_form
|
||||
%h3
|
||||
Ajouter un commentaire
|
||||
|
||||
%h3
|
||||
Ajouter un commentaire
|
||||
=form_for [:public,(@comment || Comment.new(:commentable_id => @article.id, :commentable_type => "Article"))], :remote => true do |f|
|
||||
=f.hidden_field :commentable_id
|
||||
=f.hidden_field :commentable_type
|
||||
=f.hidden_field :parent_id
|
||||
|
||||
=form_for [:public,(@comment || Comment.new(:commentable_id => @article.id, :commentable_type => "Article"))], :remote => true do |f|
|
||||
=f.hidden_field :commentable_id
|
||||
=f.hidden_field :commentable_type
|
||||
%p
|
||||
=f.label :pseudo, "Pseudo :"
|
||||
|
||||
=f.text_field :pseudo
|
||||
|
||||
%p
|
||||
|
||||
%p
|
||||
=f.label :pseudo, "Pseudo :"
|
||||
|
||||
=f.text_field :pseudo
|
||||
|
||||
%p
|
||||
=f.label :email, "Email :"
|
||||
=f.text_field :email
|
||||
|
||||
%p
|
||||
|
||||
=f.label :email, "Email :"
|
||||
=f.text_field :email
|
||||
|
||||
%p
|
||||
=f.label :website, "Site :"
|
||||
=f.text_field :website
|
||||
|
||||
%p
|
||||
|
||||
=f.label :website, "Site :"
|
||||
=f.text_field :website
|
||||
|
||||
%p
|
||||
|
||||
=f.label :comment, "Commentaire :"
|
||||
=f.text_area :comment, :style => "width:98%;height:200px;"
|
||||
|
||||
|
||||
|
||||
|
||||
=f.submit "Envoyer", :class => "submit"
|
||||
=f.label :comment, "Commentaire :"
|
||||
=f.text_area :comment, :style => "width:98%;height:200px;"
|
||||
|
||||
|
||||
|
||||
|
||||
=f.submit "Envoyer", :class => "submit btn"
|
@ -1,12 +1,8 @@
|
||||
$("#comment_form").html("<%= escape_javascript(render(:partial => "form")) %>");
|
||||
|
||||
$("#comments").html("<%= escape_javascript(render(@comment.commentable.comments.recents)) %>");
|
||||
$("#comments").html("<%= escape_javascript(render(@comment.commentable.comments.where(:enabled => true).order("created_at DESC"))) %>");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$(document.body).animate({
|
||||
'scrollTop': ( $("#comment_<%= @comment_id %>").offset().top - 150)
|
||||
}, 700);
|
||||
$('#comments').html("<%= escape_javascript(render(@comment.commentable.comments.where(:enabled => true, :parent_id => nil).order("created_at DESC")))%>");
|
||||
$(".add_comment").show();
|
9
app/views/public/comments/new.js.erb
Normal file
9
app/views/public/comments/new.js.erb
Normal file
@ -0,0 +1,9 @@
|
||||
$("#comment_form").remove();
|
||||
|
||||
<% if @comment.parent_id == nil %>
|
||||
$('#comments').append("<%= escape_javascript(render(:partial => "form"))%>");
|
||||
|
||||
<% else %>
|
||||
$('#comment_<%= @comment.parent_id %>').children(".child_comments").append("<%= escape_javascript(render(:partial => "form"))%>");
|
||||
|
||||
<% end %>
|
5
db/migrate/20150411203736_add_parent_id_to_comments.rb
Normal file
5
db/migrate/20150411203736_add_parent_id_to_comments.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddParentIdToComments < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :comments, :parent_id, :integer
|
||||
end
|
||||
end
|
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150411165401) do
|
||||
ActiveRecord::Schema.define(version: 20150411203736) do
|
||||
|
||||
create_table "admins", force: :cascade do |t|
|
||||
t.string "email", limit: 255, default: "", null: false
|
||||
@ -106,6 +106,9 @@ ActiveRecord::Schema.define(version: 20150411165401) do
|
||||
t.integer "image_file_id", limit: 4
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "parent_id", limit: 4
|
||||
t.integer "position", limit: 4
|
||||
t.boolean "front_page", limit: 1
|
||||
end
|
||||
|
||||
create_table "cel_tables", force: :cascade do |t|
|
||||
@ -147,6 +150,7 @@ ActiveRecord::Schema.define(version: 20150411165401) do
|
||||
t.integer "user_id", limit: 4
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "parent_id", limit: 4
|
||||
end
|
||||
|
||||
add_index "comments", ["commentable_id"], name: "index_comments_on_commentable_id", using: :btree
|
||||
|
Loading…
x
Reference in New Issue
Block a user