comments
This commit is contained in:
parent
c99b993fb5
commit
27d7568a83
@ -106,3 +106,45 @@ article{
|
|||||||
font-size:1em;
|
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
|
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
|
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
|
if @comment.save
|
||||||
commentable = @comment.commentable
|
commentable = @comment.commentable
|
||||||
@comment_id = @comment.id
|
@comment_id = @comment.id
|
||||||
|
@ -10,6 +10,7 @@ class Comment < ActiveRecord::Base
|
|||||||
|
|
||||||
scope :recents, -> {where("enabled = ?",true ).order("created_at ASC")}
|
scope :recents, -> {where("enabled = ?",true ).order("created_at ASC")}
|
||||||
|
|
||||||
|
acts_as_tree
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
#comments
|
#comments
|
||||||
%h2 Commentaires
|
%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"
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,18 +2,19 @@
|
|||||||
%aside=gravatar_image_tag(comment.email? ? comment.email : comment.pseudo, :gravatar => {:default => "http://#{HOSTNAME}/default_avatar.jpg"})
|
%aside=gravatar_image_tag(comment.email? ? comment.email : comment.pseudo, :gravatar => {:default => "http://#{HOSTNAME}/default_avatar.jpg"})
|
||||||
|
|
||||||
|
|
||||||
%p.header
|
.comment_body
|
||||||
|
%div.header
|
||||||
Commentaire de
|
.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
|
%strong
|
||||||
|
|
||||||
-if comment.website?
|
-if comment.website?
|
||||||
=link_to comment.pseudo, comment.website, :target => "_blank"
|
=link_to(comment.pseudo, comment.website, :target => "_blank")+","
|
||||||
-else
|
-else
|
||||||
=comment.pseudo
|
=comment.pseudo+","
|
||||||
|
|
||||||
|
|
||||||
%time.updated{:datetime => Time.now, :pubdate => true}
|
%time.updated{:datetime => Time.now, :pubdate => true}
|
||||||
envoyé
|
|
||||||
="le "+l(comment.created_at, :format => :human_date)
|
="le "+l(comment.created_at, :format => :human_date)
|
||||||
|
|
||||||
|
|
||||||
@ -21,6 +22,8 @@
|
|||||||
|
|
||||||
%blockquote=simple_format comment.comment
|
%blockquote=simple_format comment.comment
|
||||||
|
|
||||||
|
.child_comments
|
||||||
|
=render comment.children.where(:enabled => true).order(:created_at)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
|||||||
|
#comment_form.comment_form
|
||||||
%h3
|
%h3
|
||||||
Ajouter un commentaire
|
Ajouter un commentaire
|
||||||
|
|
||||||
=form_for [:public,(@comment || Comment.new(:commentable_id => @article.id, :commentable_type => "Article"))], :remote => true do |f|
|
=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_id
|
||||||
=f.hidden_field :commentable_type
|
=f.hidden_field :commentable_type
|
||||||
|
=f.hidden_field :parent_id
|
||||||
|
|
||||||
%p
|
%p
|
||||||
=f.label :pseudo, "Pseudo :"
|
=f.label :pseudo, "Pseudo :"
|
||||||
@ -29,4 +30,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
=f.submit "Envoyer", :class => "submit"
|
=f.submit "Envoyer", :class => "submit btn"
|
@ -1,12 +1,8 @@
|
|||||||
$("#comment_form").html("<%= escape_javascript(render(:partial => "form")) %>");
|
$("#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"))) %>");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$('#comments').html("<%= escape_javascript(render(@comment.commentable.comments.where(:enabled => true, :parent_id => nil).order("created_at DESC")))%>");
|
||||||
|
$(".add_comment").show();
|
||||||
|
|
||||||
$(document.body).animate({
|
|
||||||
'scrollTop': ( $("#comment_<%= @comment_id %>").offset().top - 150)
|
|
||||||
}, 700);
|
|
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.
|
# 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|
|
create_table "admins", force: :cascade do |t|
|
||||||
t.string "email", limit: 255, default: "", null: false
|
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.integer "image_file_id", limit: 4
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_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
|
end
|
||||||
|
|
||||||
create_table "cel_tables", force: :cascade do |t|
|
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.integer "user_id", limit: 4
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.integer "parent_id", limit: 4
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "comments", ["commentable_id"], name: "index_comments_on_commentable_id", using: :btree
|
add_index "comments", ["commentable_id"], name: "index_comments_on_commentable_id", using: :btree
|
||||||
|
Loading…
x
Reference in New Issue
Block a user