In my Schedules Controller, I have the following method:
def create
@schedule = current_user.team.create_schedule(params[:schedule])
if @schedule.save
flash[:success] = "Schedule created!"
redirect_to current_user.team
else
flash[:error] = "Sorry! Something went wrong."
render new_schedule_path
end
end
When I try to create a schedule, I get an error on the second line: undefined method `create_schedule’ for #
However, the team model has many schedules and the schedule model belongs to team so I’m not sure the problem is.
The
create_schedulemethod would be if it was a has_one association. It should be@schedule = current_user.team.schedules.build(params[:schedule])