Permalink
Browse files

Add delete feature to comments

  • Loading branch information...
1 parent a9811a9 commit 672244440c5cd926bfc737fbeed77bd617b98489 @ionmx ionmx committed Apr 17, 2012
View
BIN app/assets/images/icons/delete.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
6 app/assets/javascripts/home.js.coffee
@@ -285,6 +285,12 @@ $('.get-user')
$container.masonry({ itemSelector: '.post', columnWidth: $('.post').width() + 20 })
)
+$('.delete-comment')
+ .live('ajax:success', (data, status, xhr) ->
+ $("#" + $(this).attr('comment_entry_id')).fadeOut()
+ )
+
+
$('#get-home')
.live('click', () ->
getHome(true)
View
16 app/assets/stylesheets/posts.css.scss
@@ -110,6 +110,22 @@
.comment-display {
float: left;
}
+
+ .comment-delete-link {
+ float: right;
+ display: block;
+ width: 11px;
+ margin: 0 5px 5px 0;
+ display: none;
+ }
+
+ &:hover {
+ .comment-delete-link {
+ display: block;
+ }
+ }
+
+
.comment-content {
margin-left: 44px;
.comment-user a {
View
11 app/controllers/comments_controller.rb
@@ -40,4 +40,15 @@ def create
end
end
end
+
+ def mark_as_deleted
+ @comment = Comment.find(params[:id])
+ if current_user.id != @comment.user_id
+ raise "The current user is not the owner of the comment"
+ end
+ @comment.status = Comment::DELETED
+ @comment.save
+ render :inline => 'true'
+ end
+
end
View
3 app/models/comment.rb
@@ -1,4 +1,7 @@
class Comment < ActiveRecord::Base
belongs_to :post
belongs_to :user
+
+ ACTIVE = 1
+ DELETED = 2
end
View
3 app/models/post.rb
@@ -20,4 +20,7 @@ class Post < ActiveRecord::Base
has_one :user_badge
+ ACTIVE = 1
+ DELETED = 2
+
end
View
3 app/views/posts/_comment.html.haml
@@ -1,6 +1,9 @@
.comment-entry{:id => "comment_#{comment.id}"}
.comment-display
= image_tag comment.user.image_url(:small).to_s, :width => 32, :height => 32, :class => "profile-picture-small"
+ - if comment.user_id == current_user.id
+ .comment-delete-link
+ = link_to image_tag("/assets/icons/delete.png"), {:controller => "comments", :action => "mark_as_deleted", :id => comment.id}, :method => :post, :remote => true, :class => 'delete-comment', :'data-type' => 'html', :comment_entry_id => "comment_#{comment.id}"
.comment-content
%span.comment-user= link_to comment.user.display_name, {:controller => "users", :action => "profile", :username => "#{comment.user.username}"}, :method => :get, :remote => true, :class => 'get-user', :'data-type' => 'html', :username => "#{comment.user.username}"
%span.separator= "-"
View
2 app/views/posts/_post.html.haml
@@ -26,7 +26,7 @@
.post-comments{:id => "post-#{post.id}-comments"}
- last_comment = 0
- - post.comments.each do |comment|
+ - post.comments.where(:status => Comment::ACTIVE).each do |comment|
- last_comment = comment.id
= render :partial => 'posts/comment', :locals => {:comment => comment }
.post-comment-form
View
1 config/routes.rb
@@ -24,6 +24,7 @@
match 'p/:id' => 'posts#show'
resources :posts
+ match 'comments/delete/:id' => 'comments#mark_as_deleted'
resources :comments
match 'users/upcoming_birthdays' => 'users#upcoming_birthdays'
View
5 db/migrate/20120417185759_add_status_to_comments.rb
@@ -0,0 +1,5 @@
+class AddStatusToComments < ActiveRecord::Migration
+ def change
+ add_column :comments, :status, :integer, :default => 1
+ end
+end
View
96 db/schema.rb
@@ -11,24 +11,25 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120326193627) do
+ActiveRecord::Schema.define(:version => 20120417185759) do
create_table "badges", :force => true do |t|
t.string "name"
t.string "message"
t.string "earn_script"
t.string "image"
t.integer "status", :default => 1
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
create_table "comments", :force => true do |t|
t.integer "post_id"
t.integer "user_id"
t.text "content"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.integer "status", :default => 1
end
add_index "comments", ["post_id"], :name => "index_comments_on_post_id"
@@ -39,8 +40,8 @@
t.string "code"
t.string "lat", :limit => 20
t.string "long", :limit => 20
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
create_table "group_types", :force => true do |t|
@@ -50,8 +51,8 @@
t.integer "required", :default => 1
t.integer "display_in", :default => 1
t.integer "status", :default => 1
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
create_table "groups", :force => true do |t|
@@ -61,8 +62,8 @@
t.string "description"
t.integer "position"
t.integer "status", :default => 1
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
add_index "groups", ["group_type_id"], :name => "index_groups_on_group_type_id"
@@ -75,8 +76,8 @@
t.integer "can_modify_others", :default => 0
t.integer "can_admin", :default => 0
t.integer "status", :default => 1
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
add_index "memberships", ["group_id"], :name => "index_memberships_on_group_id"
@@ -85,8 +86,8 @@
create_table "page_groups", :force => true do |t|
t.integer "page_id"
t.integer "group_id"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
add_index "page_groups", ["group_id"], :name => "index_page_groups_on_group_id"
@@ -101,8 +102,8 @@
t.text "content"
t.integer "page_id"
t.integer "status", :default => 1, :null => false
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
add_index "pages", ["group_id"], :name => "index_pages_on_group_id"
@@ -121,26 +122,26 @@
t.string "image"
t.string "lat", :limit => 20
t.string "long", :limit => 20
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
add_index "post_events", ["post_id"], :name => "index_post_events_on_post_id"
create_table "post_files", :force => true do |t|
t.integer "post_id"
t.string "file"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
add_index "post_files", ["post_id"], :name => "index_post_files_on_post_id"
create_table "post_groups", :force => true do |t|
t.integer "post_id"
t.integer "group_id"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
add_index "post_groups", ["group_id"], :name => "index_post_groups_on_group_id"
@@ -151,8 +152,8 @@
t.string "link"
t.text "description"
t.string "image"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
add_index "post_links", ["post_id"], :name => "index_post_links_on_post_id"
@@ -161,8 +162,8 @@
t.integer "post_id"
t.string "photo"
t.string "description"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
add_index "post_photos", ["post_id"], :name => "index_post_photos_on_post_id"
@@ -171,8 +172,8 @@
t.string "name", :null => false
t.integer "category", :default => 0
t.integer "status", :default => 1
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
add_index "post_types", ["name"], :name => "index_post_types_on_name"
@@ -184,8 +185,8 @@
t.text "content", :null => false
t.string "limited"
t.integer "status", :default => 1, :null => false
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
add_index "posts", ["group_id"], :name => "index_posts_on_group_id"
@@ -196,17 +197,17 @@
t.string "code"
t.string "lat", :limit => 20
t.string "long", :limit => 20
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
create_table "user_badges", :force => true do |t|
t.integer "user_id"
t.integer "badge_id"
t.integer "post_id"
t.integer "status", :default => 1
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
add_index "user_badges", ["badge_id"], :name => "index_user_badges_on_badge_id"
@@ -240,13 +241,34 @@
t.string "long", :limit => 20
t.string "image"
t.integer "status", :default => 1, :null => false
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
add_index "users", ["country_id"], :name => "index_users_on_country_id"
add_index "users", ["email"], :name => "index_users_on_email"
add_index "users", ["state_id"], :name => "index_users_on_state_id"
add_index "users", ["username"], :name => "index_users_on_username"
+ create_table "xg", :id => false, :force => true do |t|
+ t.integer "id", :default => 0, :null => false
+ t.integer "nid", :default => 0
+ end
+
+ create_table "xu", :id => false, :force => true do |t|
+ t.integer "id", :default => 0, :null => false
+ t.integer "nid", :default => 0
+ end
+
+ create_table "xxx", :id => false, :force => true do |t|
+ t.string "empleado"
+ t.datetime "alta", :null => false
+ end
+
+ create_table "xxxx", :id => false, :force => true do |t|
+ t.string "empleado"
+ t.datetime "alta1", :null => false
+ t.integer "alta", :default => 0
+ end
+
end

0 comments on commit 6722444

Please sign in to comment.