Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
canvas-demo-techex17/sis-app/app/controllers/courses_controller.rb
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
76 lines (66 sloc)
1.89 KB
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 CoursesController < ApplicationController | |
before_action :set_course, only: [:show, :edit, :update, :destroy] | |
# GET /courses | |
# GET /courses.json | |
def index | |
@courses = Course.all | |
end | |
# GET /courses/1 | |
# GET /courses/1.json | |
def show | |
end | |
# GET /courses/new | |
def new | |
@course = Course.new | |
@users = User.all | |
end | |
# GET /courses/1/edit | |
def edit | |
@users = User.all | |
end | |
# POST /courses | |
# POST /courses.json | |
def create | |
@course = Course.new(course_params) | |
respond_to do |format| | |
if @course.save | |
format.html { redirect_to @course, notice: 'Course was successfully created.' } | |
format.json { render :show, status: :created, location: @course } | |
else | |
format.html { render :new } | |
format.json { render json: @course.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PATCH/PUT /courses/1 | |
# PATCH/PUT /courses/1.json | |
def update | |
respond_to do |format| | |
if @course.update(course_params) | |
format.html { redirect_to @course, notice: 'Course was successfully updated.' } | |
format.json { render :show, status: :ok, location: @course } | |
else | |
format.html { render :edit } | |
format.json { render json: @course.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /courses/1 | |
# DELETE /courses/1.json | |
def destroy | |
@course.destroy | |
respond_to do |format| | |
format.html { redirect_to courses_url, notice: 'Course was successfully destroyed.' } | |
format.json { head :no_content } | |
end | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_course | |
@course = Course.find(params[:id]) | |
end | |
# Never trust parameters from the scary internet, only allow the white list through. | |
def course_params | |
params.require(:course).permit(:course_name, :course_number, :user_ids => []) | |
end | |
end |