Advertisement
ramondiniz27

Untitled

Sep 3rd, 2017
1,610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.13 KB | None | 0 0
  1. class Shared::OrdersController < ApplicationController
  2.     layout 'admin/panel'
  3.     before_action :set_order , only: [:edit , :update, :show, :destroy]
  4.  
  5.   def index
  6.     @orders = Order.all
  7.   end
  8.  
  9.   def new
  10.     @order = Order.new
  11.   end
  12.  
  13.   def create
  14.     @order = Order.new(params_order)
  15.     if @order.save
  16.         redirect_to shared_orders_path, notice: "Pedido Salvo com sucesso!!"
  17.     else
  18.         render :new
  19.     end
  20.   end
  21.  
  22.   def edit     
  23.   end
  24.  
  25.   def update
  26.     if @order.update(params_order)
  27.             redirect_to shared_orders_path, notice: "Pedido Editado com sucesso!!"
  28.         else
  29.             render :edit
  30.         end
  31.   end
  32.  
  33.   def show
  34.   end
  35.  
  36.   def destroy
  37.     if @order.destroy
  38.       redirect_to shared_orders_path, notice: "Pedido excluido com sucesso!!"
  39.     else
  40.       render :index, notice: "Erro ao Excluir Pedido"
  41.     end
  42.   end
  43.  
  44. private
  45.  
  46.   def set_order
  47.     @order = Order.find(params[:id])
  48.   end
  49.  
  50.   def params_order
  51.   params.require(:order).permit(
  52.     :numero_orcamento,
  53.     :numero_pedido,
  54.     :nome_cliente,
  55.     :codigo_rastreio,
  56.     :link_pedido,
  57.     :status,
  58.     :data_aprovacao,
  59.     :modo_envio,
  60.     :total)
  61.   end
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement