Skip to content

Instantly share code, notes, and snippets.

@RachelSa
Created August 12, 2017 23:48
Show Gist options
  • Save RachelSa/3ff74d7dd219327631dfc763dfc7521f to your computer and use it in GitHub Desktop.
Save RachelSa/3ff74d7dd219327631dfc763dfc7521f to your computer and use it in GitHub Desktop.
class ClassroomsController < ApplicationController
def update
@classroom = Classroom.find(params[:id])
if @classroom.update(classroom_params)
program_ids = classroom_program_params[:program_ids].delete_if {|program| program == ""}
@programs = program_ids.map {|id| Program.find(id)}
@classroom.update(programs: @programs)
redirect_to users_path, :notice => "#{@classroom.name} updated"
else
flash[:notice] = "Classrooms must have a name"
@programs = Program.all
render :edit
end
end
private
def classroom_program_params
params.require(:classroom).permit({:program_ids => []})
end
def classroom_params
params.require(:classroom).permit(:name, :location, :map_url, :image_url, :description, :longitude, :latitude, :google_address, :phone)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment