Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ group :test do
end

gem "tailwindcss-rails", "~> 4.4"
gem "faker", "~> 3.8", group: :development
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ GEM
erubi (1.13.1)
et-orbi (1.4.0)
tzinfo
faker (3.8.0)
i18n (>= 1.8.11, < 2)
ffi (1.17.4-aarch64-linux-gnu)
ffi (1.17.4-aarch64-linux-musl)
ffi (1.17.4-arm-linux-gnu)
Expand Down Expand Up @@ -405,6 +407,7 @@ DEPENDENCIES
bundler-audit
capybara
debug
faker (~> 3.8)
image_processing (~> 1.2)
importmap-rails
jbuilder
Expand Down Expand Up @@ -461,6 +464,7 @@ CHECKSUMS
erb (6.0.3) sha256=e43685a8a0a0ea6a924871b2162e8953ef73147ce46b75b36d1f6774fd286e91
erubi (1.13.1) sha256=a082103b0885dbc5ecf1172fede897f9ebdb745a4b97a5e8dc63953db1ee4ad9
et-orbi (1.4.0) sha256=6c7e3c90779821f9e3b324c5e96fda9767f72995d6ae435b96678a4f3e2de8bc
faker (3.8.0) sha256=c147b308df73a90f27a4fc84f18d4c22ef0ad9c2a64b2b61c86fd0ca71753efc
ffi (1.17.4-aarch64-linux-gnu) sha256=b208f06f91ffd8f5e1193da3cae3d2ccfc27fc36fba577baf698d26d91c080df
ffi (1.17.4-aarch64-linux-musl) sha256=9286b7a615f2676245283aef0a0a3b475ae3aae2bb5448baace630bb77b91f39
ffi (1.17.4-arm-linux-gnu) sha256=d6dbddf7cb77bf955411af5f187a65b8cd378cb003c15c05697f5feee1cb1564
Expand Down
75 changes: 75 additions & 0 deletions app/controllers/students_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
class StudentsController < ApplicationController
before_action :set_school, only: %i[ index new create ]
before_action :set_student, only: %i[ show edit update destroy ]

# GET /students or /students.json
def index
@students = @school.students.all
end

# GET /students/1 or /students/1.json
def show
end

# GET /students/new
def new
@student = @school.students.build
end

# GET /students/1/edit
def edit
end

# POST /students or /students.json
def create
@student = @school.students.build(student_params)

respond_to do |format|
if @student.save
format.html { redirect_to @student, notice: "Student was successfully created." }
format.json { render :show, status: :created, location: @student }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @student.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /students/1 or /students/1.json
def update
respond_to do |format|
if @student.update(student_params)
format.html { redirect_to @student, notice: "Student was successfully updated.", status: :see_other }
format.json { render :show, status: :ok, location: @student }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @student.errors, status: :unprocessable_entity }
end
end
end

# DELETE /students/1 or /students/1.json
def destroy
@student.destroy!

respond_to do |format|
format.html { redirect_to school_students_path(@student.school_id), notice: "Student was successfully destroyed.", status: :see_other }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_student
@student = Student.find(params.expect(:id))
end

def set_school
@school = School.find(params.expect(:school_id))
end

# Only allow a list of trusted parameters through.
def student_params
params.expect(student: [ :first_name, :last_name, :email, :grade_level, :gender ])
end
end
1 change: 1 addition & 0 deletions app/models/school.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class School < ApplicationRecord
has_many :students, dependent: :destroy
validates :name, presence: true
end
7 changes: 7 additions & 0 deletions app/models/student.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Student < ApplicationRecord
belongs_to :school

enum :gender, %i[male female other].index_by(&:itself)

validates :first_name, :last_name, :grade_level, presence: true
end
3 changes: 2 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
</head>

<body>
<main class="container mx-auto mt-28 px-5">
<main class="container mx-auto p-5">
<%= yield %>
</main>
</body>

</html>
28 changes: 15 additions & 13 deletions app/views/passwords/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
<div class="card card-border bg-base-100 shadow-md w-96 mx-auto">
<section class="flex items-center justify-center mt-28">
<div class="card card-border bg-base-100 shadow-md w-96">

<div class="card-body">
<h2 class="card-title">
Update your password
</h2>
<%= form_with url: password_path(params[:token]), method: :put do |form| %>
<div class="flex flex-col gap-2">
<%= form.password_field :password, required: true, autocomplete: "new-password", placeholder: "Enter new password", maxlength: 72, class: "input w-full" %>
<%= form.password_field :password_confirmation, required: true, autocomplete: "new-password", placeholder: "Repeat new password", maxlength: 72, class: "input w-full" %>
<%= form.submit "Save", class: "btn btn-primary w-full" %>
</div>
<% end %>
<div class="card-body">
<h2 class="card-title">
Update your password
</h2>
<%= form_with url: password_path(params[:token]), method: :put do |form| %>
<div class="flex flex-col gap-2">
<%= form.password_field :password, required: true, autocomplete: "new-password", placeholder: "Enter new password", maxlength: 72, class: "input w-full" %>
<%= form.password_field :password_confirmation, required: true, autocomplete: "new-password", placeholder: "Repeat new password", maxlength: 72, class: "input w-full" %>
<%= form.submit "Save", class: "btn btn-primary w-full" %>
</div>
<% end %>
</div>
</div>
</div>
</section>
26 changes: 14 additions & 12 deletions app/views/passwords/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
<div class="card card-border bg-base-100 shadow-md w-96 mx-auto">
<section class="flex items-center justify-center mt-28">
<div class="card card-border bg-base-100 shadow-md w-96">

<div class="card-body">
<h2 class="card-title">
Forgot your password?
</h2>
<%= form_with url: passwords_path do |form| %>
<div class="flex flex-col gap-2">
<%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address], class: "input w-full" %>
<br>
<%= form.submit "Email reset instructions", class: "btn btn-primary w-full" %>
<% end %>
<div class="card-body">
<h2 class="card-title">
Forgot your password?
</h2>
<%= form_with url: passwords_path do |form| %>
<div class="flex flex-col gap-2">
<%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address], class: "input w-full" %>
<br>
<%= form.submit "Email reset instructions", class: "btn btn-primary w-full" %>
<% end %>
</div>
</div>
</div>
</div>
</section>
30 changes: 14 additions & 16 deletions app/views/schools/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
<%= form_with(model: school) do |form| %>
<% if school.errors.any? %>
<div style="color: red">
<h2><%= pluralize(school.errors.count, "error") %> prohibited this school from being saved:</h2>
<div class="flex flex-col gap-2">
<% if school.errors.any? %>
<div style="color: red">
<h2><%= pluralize(school.errors.count, "error") %> prohibited this school from being saved:</h2>

<ul>
<% school.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>
<ul>
<% school.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div>
<%= form.label :name, style: "display: block" %>
<%= form.text_field :name %>
</div>
<%= form.label :name, class: "label" %>
<%= form.text_field :name, class: "input w-full" %>

<div>
<%= form.submit %>
<%= form.submit class: "btn btn-primary w-full" %>
</div>
<% end %>
25 changes: 14 additions & 11 deletions app/views/schools/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<% content_for :title, "Editing school" %>

<h1>Editing school</h1>

<%= render "form", school: @school %>

<br>

<div>
<%= link_to "Show this school", @school %> |
<%= link_to "Back to schools", schools_path %>
</div>
<nav class="breadcrumbs text-sm">
<ul>
<li><%= link_to "All Schools", schools_path %></li>
<li>Edit School</li>
</ul>
</nav>
<section class="py-10 flex items-center justify-center">
<div class="card card-border bg-base-100 shadow-md w-96">
<div class="card-body">
<h1 class="card-title">Edit School</h1>
<%= render "form", school: @school %>
</div>
</div>
</section>
4 changes: 2 additions & 2 deletions app/views/schools/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ul id="schools" class="list bg-base-100 rounded-box shadow-md">
<% @schools.each do |school| %>
<li class="list-row">
<%= link_to school.name, school, class: "link" %>
<%= link_to school.name, school_students_path(school), class: "link" %>
</li>
<% end %>
</ul>
</ul>
23 changes: 14 additions & 9 deletions app/views/schools/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<% content_for :title, "New school" %>

<h1>New school</h1>

<%= render "form", school: @school %>

<br>

<div>
<%= link_to "Back to schools", schools_path %>
</div>
<nav class="breadcrumbs text-sm">
<ul>
<li><%= link_to "All Schools", schools_path %></li>
<li>New School</li>
</ul>
</nav>
<section class="py-10 flex items-center justify-center">
<div class="card card-border bg-base-100 shadow-md w-96">
<div class="card-body">
<h1 class="card-title">New School</h1>
<%= render "form", school: @school %>
</div>
</div>
</section>
32 changes: 17 additions & 15 deletions app/views/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
<%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %>
<div class="card card-border bg-base-100 shadow-md w-96 mx-auto">
<section class="flex items-center justify-center mt-28">
<div class="card card-border bg-base-100 shadow-md w-96">

<div class="card-body">
<h2 class="card-title">
Login
</h2>
<%= form_with url: session_path do |form| %>
<div class="flex flex-col gap-2">
<div class="card-body">
<h2 class="card-title">
Login
</h2>
<%= form_with url: session_path do |form| %>
<div class="flex flex-col gap-2">

<%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address], class: "input w-full" %>
<%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72, class: "input w-full" %>
<div class="card-actions flex-col gap-2">
<%= form.submit "Sign in", class: "btn btn-primary w-full" %>
<%= link_to "Forgot password?", new_password_path, class: "btn btn-link" %>
<%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address], class: "input w-full" %>
<%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72, class: "input w-full" %>
<div class="card-actions flex-col gap-2">
<%= form.submit "Sign in", class: "btn btn-primary w-full" %>
<%= link_to "Forgot password?", new_password_path, class: "btn btn-link" %>
</div>
</div>
</div>
<% end %>
<% end %>
</div>
</div>
</div>
</section>

32 changes: 32 additions & 0 deletions app/views/students/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<%= form_with(model: [@school, student]) do |form| %>
<div class="flex flex-col gap-2">
<% if student.errors.any? %>
<div style="color: red">
<h2><%= pluralize(student.errors.count, "error") %> prohibited this student from being saved:</h2>

<ul>
<% student.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<%= form.label :first_name, class: "label" %>
<%= form.text_field :first_name, class: "input w-full" %>

<%= form.label :last_name, class: "label" %>
<%= form.text_field :last_name, class: "input w-full" %>

<%= form.label :email, class: "label" %>
<%= form.text_field :email, class: "input w-full" %>

<%= form.label :grade_level, class: "label" %>
<%= form.number_field :grade_level, class: "input w-full" %>

<%= form.label :gender, class: "label" %>
<%= form.text_field :gender, class: "input w-full" %>

<%= form.submit class: "btn btn-primary" %>
</div>
<% end %>
27 changes: 27 additions & 0 deletions app/views/students/_student.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div id="<%= dom_id student %>">
<div>
<strong>First name:</strong>
<%= student.first_name %>
</div>

<div>
<strong>Last name:</strong>
<%= student.last_name %>
</div>

<div>
<strong>Email:</strong>
<%= student.email %>
</div>

<div>
<strong>Grade level:</strong>
<%= student.grade_level %>
</div>

<div>
<strong>Gender:</strong>
<%= student.gender %>
</div>

</div>
Loading