Created
November 6, 2012 12:02
-
-
Save davetheninja/4024268 to your computer and use it in GitHub Desktop.
Managing Value Object and non standard JSON input
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 Api::ScheduledCoursesController < Api::BaseController | |
def create | |
@scheduled_course = ScheduledCourse.create!({ | |
course: get_course, | |
location: build_location | |
}) | |
render :create, status: :created | |
end | |
private | |
def get_course | |
course_params = params[:course] | |
Course.find_by_id(course_params[:id]) unless course_params.nil? | |
end | |
def build_location | |
location_params = params[:location] | |
return Location.new({}) if location_params.nil? | |
Location.new(location_params) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment