Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add students controller, test and view to display student cash balance #159

Merged
merged 1 commit into from
Jun 1, 2024
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
11 changes: 11 additions & 0 deletions app/controllers/students_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class StudentsController < ApplicationController
before_action :set_student, only: %i[show]

def show; end

private

def set_student
@student = Student.find(params[:id])
end
end
7 changes: 7 additions & 0 deletions app/views/students/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div>
<h1>Email: <%= @student.email %></h1>
</div>

<div>
<h1>Cash Balance: <%= number_to_currency(@student&.portfolio&.cash_balance) %></h1>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
devise_for :users
resources :classrooms
resources :schools
resources :students, only: [:show]
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
Expand Down
12 changes: 12 additions & 0 deletions test/controllers/students_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'test_helper'

class StudentsControllerTest < ActionDispatch::IntegrationTest
setup do
@student = users(:one)
end

test 'should show student' do
get student_url(@student)
assert_response :success
end
end