Advertisement
ramondiniz27

Untitled

Aug 29th, 2017
1,344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.99 KB | None | 0 0
  1. class Shared::EventsController < ApplicationController
  2.     layout 'admin/panel'
  3.     before_action :set_event , only: [:edit , :update, :show ,:destroy]
  4.   def index
  5.     @events = Event.all
  6.   end
  7.  
  8.   def new
  9.     @event = Event.new
  10.   end
  11.  
  12.   def create
  13.     @event = Event.new(params_event)
  14.     if @event.save
  15.         redirect_to shared_events_path, notice: "Pedido Salvo com sucesso!!"
  16.     else
  17.         render :new
  18.     end
  19.   end
  20.  
  21.   def edit     
  22.   end
  23.  
  24.   def update
  25.     if @event.update(params_event)
  26.             redirect_to shared_events_path, notice: "Pedido Editado com sucesso!!"
  27.         else
  28.             render :edit
  29.         end
  30.   end
  31.  
  32.   def set_event
  33.     @event = Event.find(params[:id])
  34.   end
  35.  
  36.  
  37.     def show
  38.     end
  39.  
  40.   def destroy
  41.     if @event.destroy
  42.       redirect_to shared_events_path, notice: "Pedido excluido com sucesso!!"
  43.     else
  44.       render :index
  45.     end
  46.   end
  47.  
  48.  
  49.     private
  50.  
  51.     def params_event
  52.     params.require(:event).permit(
  53.         :title,
  54.         :data_inicio,
  55.         :data_fim,
  56.         :description
  57.         )
  58.     end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement