From c9fa5d82c592f70a6c7e97d604d5ad8815477ddc Mon Sep 17 00:00:00 2001 From: Ryan Bedard Date: Mon, 18 Nov 2013 16:11:22 -0500 Subject: [PATCH] fixed delete --- app/controllers/microposts_controller.rb | 3 ++- app/controllers/tickets_controller.rb | 30 ++++++++++++++++++++++++ app/models/micropost.rb | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 app/controllers/tickets_controller.rb diff --git a/app/controllers/microposts_controller.rb b/app/controllers/microposts_controller.rb index 2e65fb0..440bb77 100644 --- a/app/controllers/microposts_controller.rb +++ b/app/controllers/microposts_controller.rb @@ -1,5 +1,6 @@ class MicropostsController < ApplicationController - before_action :signed_in_user + before_action :signed_in_user, only: [:create, :destroy] + before_action :correct_user, only: :destroy def create @micropost = current_user.microposts.build(micropost_params) diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb new file mode 100644 index 0000000..b790083 --- /dev/null +++ b/app/controllers/tickets_controller.rb @@ -0,0 +1,30 @@ +class TicketsController < ApplicationController + before_action :signed_in_user + + def create + @ticket = current_user.ticket.build(ticket_params) + if @ticket.save + flash[:success] = "Ticket Posted!" + redirect_to root_url + else + @feed_items = [] + render 'static_pages/home' + end + end + + def destroy + @ticket.destroy + redirect_to root_url + end + + private + + def ticket_params + params.require(:ticket).permit() + end + def correct_user + @ticket = current_user.tickets.find_by(id: params[:id]) + redirect_to root_url if @ticket.nil? + end + +end \ No newline at end of file diff --git a/app/models/micropost.rb b/app/models/micropost.rb index 70493fe..de034b6 100644 --- a/app/models/micropost.rb +++ b/app/models/micropost.rb @@ -1,4 +1,5 @@ class Micropost < ActiveRecord::Base + before_save { } belongs_to :user default_scope -> { order('created_at DESC') } validates :content, presence: true, length: { maximum: 140 }