diff --git a/app/controllers/micro_posts_controller.rb b/app/controllers/micro_posts_controller.rb index 9edfd0d..34061c2 100644 --- a/app/controllers/micro_posts_controller.rb +++ b/app/controllers/micro_posts_controller.rb @@ -34,4 +34,16 @@ class MicroPostsController < ApplicationController redirect_to microposts_path end + def delete + @user = current_user + micropost_id = params[:micropost_id].to_i + micropost_id = @user.micro_posts.find_by(id: micropost_id) + if micropost_id + micropost_id.destroy + render json: {status:true} + else + render json: {status:false} + end + end + end diff --git a/app/helpers/micro_posts_helper.rb b/app/helpers/micro_posts_helper.rb index 53ed12d..9b5c3f2 100644 --- a/app/helpers/micro_posts_helper.rb +++ b/app/helpers/micro_posts_helper.rb @@ -9,6 +9,7 @@ module MicroPostsHelper if !micro_posts.empty? micro_posts.each do |micro_post| x = Hash.new() + x["postid"] = micro_post.id x["title"] = micro_post.title x["content"] = micro_post.content case micro_post.post_type diff --git a/app/models/micro_post.rb b/app/models/micro_post.rb index 2a2be7e..2ece845 100644 --- a/app/models/micro_post.rb +++ b/app/models/micro_post.rb @@ -1,4 +1,4 @@ class MicroPost < ApplicationRecord - belongs_to :user, dependent: :destroy + belongs_to :user has_many :comments, class_name: 'Comment', foreign_key: 'micro_post_id', dependent: :destroy end diff --git a/app/models/user.rb b/app/models/user.rb index f387ea9..91adcdc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,8 +5,8 @@ class User < ApplicationRecord self.picurl = 'images/avatars/default/avatar.png' end - has_many :send_messages, class_name: 'Message', foreign_key: 'send_user' - has_many :recieve_messages, class_name: 'Message', foreign_key: 'recieve_user' + has_many :send_messages, class_name: 'Message', foreign_key: 'send_user', dependent: :destroy + has_many :recieve_messages, class_name: 'Message', foreign_key: 'recieve_user', dependent: :destroy has_many :micro_posts, dependent: :destroy has_many :comments, class_name: 'Comment', foreign_key: 'user_id', dependent: :destroy diff --git a/app/views/micro_posts/show.html.erb b/app/views/micro_posts/show.html.erb index 7132696..e783f00 100644 --- a/app/views/micro_posts/show.html.erb +++ b/app/views/micro_posts/show.html.erb @@ -60,8 +60,8 @@