Skip to content

Instantly share code, notes, and snippets.

@DouweM
Last active December 21, 2015 05:39
Show Gist options
  • Save DouweM/6258222 to your computer and use it in GitHub Desktop.
Save DouweM/6258222 to your computer and use it in GitHub Desktop.
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