Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Admin::TestimonialsController < ApplicationController
- before_action :authenticate_user!
- def index
- testimonials = Testimonial.all.select :id, :name, :patronymic, :surname, :userpic, :company,
- :object_photo_1, :object_photo_2, :object_photo_3,
- :video, :text, :created_at, :updated_at
- render json: testimonials, status: :ok
- end
- def create
- testimonial = Testimonial.new(t_params)
- if testimonial.save
- testimonial = find_testimonial(testimonial.id)
- render json: testimonial, status: :created
- else
- render json: {errors: testimonial.errors}, status: :bad_request
- end
- end
- def show
- testimonial = find_testimonial(params[:id])
- render json: testimonial, status: :ok
- end
- def update
- testimonial = Testimonial.find(params[:id])
- if testimonial.update_attributes(t_params)
- testimonial = find_testimonial(params[:id])
- render json: testimonial, status: :ok
- else
- render json: {errors: testimonial.errors}, status: :bad_request
- end
- end
- def destroy
- testimonial = Testimonial.find(params[:id])
- testimonial.destroy
- render json: testimonial, status: :no_content
- end
- private
- def t_params
- safe_params = params.permit :name, :patronymic, :surname, :userpic, :company,
- :object_photo_1, :object_photo_2, :object_photo_3,
- :video, :text, :id
- params = ActionController::Parameters.new(testimonial: safe_params)
- params.require(:testimonial).permit :name, :patronymic, :surname, :userpic, :company,
- :object_photo_1, :object_photo_2, :object_photo_3,
- :video, :text, :id
- end
- def find_testimonial id
- Testimonial.select(:id, :name, :patronymic, :surname, :userpic, :company,
- :object_photo_1, :object_photo_2, :object_photo_3,
- :video, :text, :created_at, :updated_at).where(id: id)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement