class MusicSessionsController < ApplicationController

  # have to be signed in currently to see this screen
  before_filter :signed_in_user

  respond_to :html

  def index
    @music_sessions = MusicSession.paginate(page: params[:page])
  end

  def show
    @music_session = MusicSession.find(params[:id])

    # use gon to pass variables into javascript
    gon.websocket_gateway_uri = Rails.application.config.websocket_gateway_uri
    gon.music_session_id = @music_session.id
  end

  def new
    @music_session = MusicSession.new
  end

  def create
    @music_session = MusicSession.new()
    @music_session.creator = current_user
    @music_session.description = params[:jam_ruby_music_session][:description]
    if @music_session.save
      flash[:success] = "Music Session created"
      redirect_to @music_session
    else
      render 'new'
    end
  end


  def edit
  end

  def update

  end

  def destroy
    MusicSession.find(params[:id]).destroy
    flash[:success] = "Jam Session deleted."
    redirect_to music_sessions_url
  end

end
