Last active
December 21, 2015 05:39
-
-
Save DouweM/6258222 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 TutorsController < ApplicationController | |
before_action :authenticate_user! | |
respond_to :html | |
def new | |
@tutor = current_user.build_tutor | |
respond_with @tutor | |
end | |
def show | |
@tutor = current_user.tutor | |
respond_with @tutor | |
end | |
def create | |
@tutor = current_user.build_tutor(tutor_params) | |
respond_with(@tutor) do |format| | |
if @tutor.save | |
flash[:success] = 'Tutor profile created!' | |
else | |
flash[:error] = 'Tutor profile not created' | |
end | |
end | |
end | |
def update | |
@tutor = current_user.tutor | |
respond_with(@tutor) do |format| | |
if @tutor.update_attributes(tutor_params) | |
flash[:success] = 'Tutor profile updated' | |
else | |
flash[:error] = 'Tutor profile not updated' | |
end | |
end | |
end | |
private | |
def tutor_params | |
params.require(:tutor).permit(:id, :description, :rate, :country) | |
end | |
end | |
class Tutor < ActiveRecord::Base | |
belongs_to :user | |
end | |
class User < ActiveRecord::Base | |
has_one :tutor, autobuild: true, dependent: :destroy | |
devise :database_authenticatable, :registerable, | |
:recoverable, :rememberable, :trackable, :validatable | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment