Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #patients_controller.rb
- class PatientsController < ApplicationController
- before_action :set_patient, only: [:show, :edit, :update, :destroy]
- # GET /patients
- def index
- @patients = Patient.all
- end
- # GET /patients/1
- def show
- end
- # GET /patients/new
- def new
- @patient = Patient.new
- end
- # GET /patients/1/edit
- def edit
- end
- # POST /patients
- def create
- @patient = Patient.new(patient_params)
- if @patient.save
- redirect_to @patient, notice: 'Patient was successfully created.'
- else
- render :new
- end
- end
- # PATCH/PUT /patients/1
- def update
- if @patient.update(patient_params)
- redirect_to @patient, notice: 'Patient was successfully updated.'
- else
- render :edit
- end
- end
- # DELETE /patients/1
- def destroy
- @patient.destroy
- redirect_to patients_url, notice: 'Patient was successfully destroyed.'
- end
- private
- # Use callbacks to share common setup or constraints between actions.
- def set_patient
- @patient = Patient.find(params[:id])
- end
- # Only allow a trusted parameter "white list" through.
- def patient_params
- params.require(:patient).permit(:fname, :lname, :mname, :dob, :medactID)
- end
- #pagination
- def index
- @patients = Patient.page(params[:page])
- end
- end
- #index.html.erb
- <p id="notice"><%= notice %></p>
- <h1>Patients</h1>
- <table>
- <thead>
- <tr>
- <th>Fname</th>
- <th>Lname</th>
- <th>Mname</th>
- <th>Dob</th>
- <th>Medactid</th>
- <th colspan="3"></th>
- </tr>
- </thead>
- <tbody>
- <% @patients.each do |patient| %>
- <tr>
- <td><%= patient.fname %></td>
- <td><%= patient.lname %></td>
- <td><%= patient.mname %></td>
- <td class="dob"><%= patient.dob %></td>
- <td><%= patient.id %></td>
- <td><%= link_to 'Show', patient %></td>
- <td><%= link_to 'Edit', edit_patient_path(patient) %></td>
- <td><%= link_to 'Destroy', patient, method: :delete, data: { confirm: 'Are you sure?' } %></td>
- </tr>
- <% end %>
- </tbody>
- </table>
- <br>
- <%= link_to 'New Patient', new_patient_path %>
- <div><%= paginate @patients%></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement