Guest User

Untitled

a guest
Dec 12th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. module ApplicationHelper
  2.  
  3. def logged_in?
  4. session[:user_id]
  5. end
  6.  
  7. def current_user
  8. if session[:user_id]
  9. return User.find(session[:user_id])
  10. end
  11. end
  12.  
  13. end
  14.  
  15.  
  16. ------------------------------------------------
  17. class PatientsController < ApplicationController
  18.  
  19. def new
  20. @patient = current_user.patients.new
  21. end
  22.  
  23. def create
  24. @patient = Patient.new(params[:patient])
  25.  
  26. if @patient.save
  27. flash[:notice] = "Patient Saved"
  28. session[:user_id] = @patient.id
  29. redirect_to patient_path(@patient)
  30. else
  31. flash[:notice] = "Try Again!"
  32. render :new
  33. end
  34. end
  35.  
  36. def show
  37. @patient = Patient.find(params[:id])
  38.  
  39. respond_to do |format|
  40. format.html # show.html.erb
  41. format.json { render json: @patient }
  42. end
  43.  
  44. # GET /products/new
  45. # GET /products/new.json
  46. end
  47.  
  48. end
  49.  
  50.  
  51. ---------------------------------------------------------------
Add Comment
Please, Sign In to add comment