Skip to content

Commit

Permalink
Merge pull request #159 from rubyforgood/show-student-funds_144
Browse files Browse the repository at this point in the history
Add students controller, test and view to display student cash balance
  • Loading branch information
h-m-m authored Jun 1, 2024
2 parents 6922fa8 + 92ae625 commit a13a097
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
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

0 comments on commit a13a097

Please sign in to comment.