class SoundTreksController < ApplicationController
  include SoundTreksHelper

  def index

  end

  def show
    @sound_trek = SoundTrek.find(params[:id])
  end

  def new
    # @sound_trek = SoundTrek.new
  end

  def edit
    @sound_trek = SoundTrek.find(params[:id])
  end

  def create
    @sound_trek = SoundTrek.new(sound_trek_params)
    if @sound_trek.save
      redirect_to @sound_trek
    else
      @errors = @sound_trek.errors.full_messages
      render "new"
    end
  end

  def update
    @sound_trek = SoundTrek.find(params[:id])
     if @sound_trek.update(sound_trek_params)
      redirect_to @sound_trek
    else
      render 'edit'
    end

        # if sound_trek_owner?(@sound_trek)

    # else
      # flash[:no_access] = "You do not have permission to edit this SoundTrek."        redirect_to @recipe
      # redirect_to @sound_trek
    # end
  end


  # def destroy
  # end


  private
  def sound_trek_params
    params.require(:sound_trek).permit(:description, :title, :location_id, :playlist_id)
  end
end

class SoundTreksController < ApplicationController
  include SoundTreksHelper

  def index

  end

  def show
    @sound_trek = SoundTrek.find(params[:id])
  end

  def new
    # @sound_trek = SoundTrek.new
  end

  def edit
    # Fix this shit
    @sound_trek = SoundTrek.find(params[:id])
    if sound_trek_owner?(@sound_trek)
      @sound_trek
    end
  end

  def create
    @sound_trek = SoundTrek.new(sound_trek_params)
    if @sound_trek.save
      redirect_to @sound_trek
    else
      @errors = @sound_trek.errors.full_messages
      render "new"
    end
  end

  def update
    @sound_trek = SoundTrek.find(params[:id])
    if sound_trek_owner?(@sound_trek)
     if @sound_trek.update(sound_trek_params)
      redirect_to @sound_trek
    else
      render 'edit'
    end

        # if sound_trek_owner?(@sound_trek)

    # else
      # flash[:no_access] = "You do not have permission to edit this SoundTrek."        redirect_to @recipe
      # redirect_to @sound_trek
    end
  end


  def destroy
    @sound_trek = SoundTrek.find(params[:id])

    if sound_trek_owner?(@sound_trek)
      @sound_trek.destroy
      redirect_to user_path(session[:user_id])
    else
      flash[:no_access] = "You do not have permission to delete this SoundTrek."
      redirect_to @sound_trek
    end
  end

  private
  def sound_trek_params
    params.require(:sound_trek).permit(:description, :title, :location_id, :playlist_id)
  end
end

Add destroy action so that a creator can delete their soundtrek
Add destroy action so that a creator can delete their soundtrek
