class Admin::TestimonialsController < Admin::BaseController

  include Admin::InheritedResource

  # To build testimonial image if image is not available
  def resource
    @testimonial = super
    @testimonial.build_testimonial_image unless @testimonial.testimonial_image
    @testimonial
  end

  # To activate the testimonial
  def activate
    respond_to do |format|
      if resource.update_attribute(:active, 'true')
        format.js {render 'referesh_datatable'}
      else
        format.js {redirect_to collection_path, alert: 'Unable to activate.'}
      end
    end
  end

  # To deactivate the testimonial
  def deactivate
    respond_to do |format|
      if resource.update_attribute(:active, 'false')
        format.js {render 'referesh_datatable'}
      else
        format.js {redirect_to collection_path, alert: 'Unable to deactivate.'}
      end
    end
  end

  private
  def permitted_params
    params.permit(testimonial: [:heading, :name, :position, :university_name, :description, testimonial_image_attributes: [:image, :id]])
  end

end
