Created
August 12, 2017 23:48
-
-
Save RachelSa/3ff74d7dd219327631dfc763dfc7521f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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