Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed delete
  • Loading branch information
rcb09003 committed Nov 18, 2013
1 parent 1216c30 commit c9fa5d8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion 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)
Expand Down
30 changes: 30 additions & 0 deletions 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
1 change: 1 addition & 0 deletions 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 }
Expand Down

0 comments on commit c9fa5d8

Please sign in to comment.