diff --git a/rails_root/app/controllers/home_controller.rb b/rails_root/app/controllers/home_controller.rb index 2c39734..997387c 100644 --- a/rails_root/app/controllers/home_controller.rb +++ b/rails_root/app/controllers/home_controller.rb @@ -3,8 +3,11 @@ # Controller for the home page class HomeController < ApplicationController def index - @survey_responses = SurveyResponse.where(profile_id: 2) # FIXME: use code below when other part works - # @survey_profile = SurveyProfile.find_by(user_id: session[:userinfo]["sub"]) - # @survey_responses = SurveyResponse.where(profile_id: session[:userinfo]["sub"]) + return if session[:userinfo].nil? + + @survey_profile = SurveyProfile.find_by(user_id: session[:userinfo]['sub']) + return if @survey_profile.nil? + + @survey_responses = SurveyResponse.where(profile_id: @survey_profile.id) end end diff --git a/rails_root/app/views/home/index.html.erb b/rails_root/app/views/home/index.html.erb index 4e8f468..0244e7d 100644 --- a/rails_root/app/views/home/index.html.erb +++ b/rails_root/app/views/home/index.html.erb @@ -4,6 +4,11 @@ <% if session[:userinfo].present? %>

<%= session[:userinfo]['name'] %> - Welcome to Our Rails App

+
+

Your Profile

+ <% if @survey_profile.present? %> + <%= render @survey_profile%> + <%end%>

Your History Responses

diff --git a/rails_root/app/views/survey_profiles/_survey_profile.html.erb b/rails_root/app/views/survey_profiles/_survey_profile.html.erb index dfb371e..7093f46 100644 --- a/rails_root/app/views/survey_profiles/_survey_profile.html.erb +++ b/rails_root/app/views/survey_profiles/_survey_profile.html.erb @@ -1,8 +1,4 @@
-

- User: - <%= survey_profile.user_id %> -

First name: diff --git a/rails_root/spec/views/home/index.html.erb_spec.rb b/rails_root/spec/views/home/index.html.erb_spec.rb index e4c0596..0038cd2 100644 --- a/rails_root/spec/views/home/index.html.erb_spec.rb +++ b/rails_root/spec/views/home/index.html.erb_spec.rb @@ -11,7 +11,7 @@ RSpec.describe 'home/index.html.erb', type: :view do it 'displays the welcome message with name' do - session[:userinfo] = { 'name' => 'Peter', 'sub' => 'testestest' } + session[:userinfo] = { 'name' => 'Peter', 'sub' => 1 } render expect(rendered).to have_text('Peter - Welcome to Our Rails App') end