jarocki_art

method create

Jul 4th, 2019
660
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Admin::TestimonialsController < ApplicationController
  2.   before_action :authenticate_user!
  3.  
  4. # . . .
  5.  
  6.   def create
  7.     testimonial = Testimonial.new(t_params)
  8.  
  9.     if testimonial.save
  10.       testimonial = find_testimonial(testimonial.id)
  11.       render json: testimonial, status: :created
  12.     else
  13.       render json: {errors: testimonial.errors}, status: :bad_request
  14.     end
  15.   end
  16.  
  17. # . . .
  18.  
  19.   private
  20.  
  21.   def params_filter
  22.     params.permit :name, :patronymic, :surname, :userpic, :company,
  23.                   :object_photo_1, :object_photo_2, :object_photo_3,
  24.                   :video, :text, :id
  25.   end
  26.  
  27.   def t_params
  28.     params.each { |param| param = nil if param == "null" }
  29.  
  30.     safe_params = params_filter
  31.     params = ActionController::Parameters.new(testimonial: safe_params)
  32.  
  33.     params.require(:testimonial).permit :name, :patronymic, :surname, :userpic, :company,
  34.                                         :object_photo_1, :object_photo_2, :object_photo_3,
  35.                                         :video, :text, :id
  36.   end
  37.  
  38. # . . .
  39.  
  40. end
RAW Paste Data