
class SpeechesController < ApplicationController
  before_action :user_is_editor?
  before_action :set_speech, only: %i[ show edit update destroy]
  layout "admin"

  def index
    @speeches = Speech.all
  end

  def show
    redirect_to speeches_url
  end

  def update
    if @speech.update(speech_params)
      redirect_to speeches_url, notice: "Texto actualizado."
    else
      render :edit, status: :unprocessable_entity
    end
  end

  def destroy
    @speech.destroy
    redirect_to speeches_url
  end

  private
    def set_speech
      @speech = Speech.find(params[:id])
    end

    def speech_params
      params.require(:speech).permit(:speech, :title, :img)
    end

end