Skip to content

Commit

Permalink
Handle destoy action
Browse files Browse the repository at this point in the history
  • Loading branch information
scaffeinate committed Jul 12, 2015
1 parent e97d257 commit e309c97
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
8 changes: 5 additions & 3 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ class EventsController < ApplicationController
before_action :authenticate_user!
before_action :set_event, only: [:show, :destroy]

respond_to :html

def new
@event = Event.new
end
Expand All @@ -24,7 +22,11 @@ def show

def destroy
@event.destroy
redirect_to root_path
@activity = params[:activity]
respond_to do |format|
format.js
format.html { redirect_to root_path }
end
end

private
Expand Down
11 changes: 6 additions & 5 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ class PostsController < ApplicationController
before_action :authenticate_user!
before_action :set_post, only: [:show, :update, :destroy]

respond_to :html

def show
@comments = @post.comments.all
end

def create
@post = Post.new(post_params) do |post|
post.user = current_user
end
@post = current_user.posts.new(post_params)
if @post.save
redirect_to root_path
else
Expand All @@ -26,6 +22,11 @@ def update

def destroy
@post.destroy
@activity = params[:activity]
respond_to do |format|
format.js
format.html { redirect_to root_path }
end
end

private
Expand Down
2 changes: 2 additions & 0 deletions app/views/events/destroy.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
console.log("#activity-<%= @activity %>");
$("#activity-<%= @activity %>").remove();
1 change: 1 addition & 0 deletions app/views/posts/destroy.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$("#activity-<%= @activity %>").remove();

0 comments on commit e309c97

Please sign in to comment.