From ca39eea326d9902216f623ad5f802d969b282fcc Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 10 Mar 2021 14:40:17 +0500 Subject: [PATCH] Add action ProfilesController#show --- app/controllers/profiles_controller.rb | 5 +++++ app/models/profile.rb | 4 ++++ app/views/profiles/show.html.erb | 11 +++++++++++ config/routes.rb | 3 ++- test/controllers/profiles_controller_test.rb | 8 ++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 app/controllers/profiles_controller.rb create mode 100644 app/views/profiles/show.html.erb create mode 100644 test/controllers/profiles_controller_test.rb diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb new file mode 100644 index 0000000..d802715 --- /dev/null +++ b/app/controllers/profiles_controller.rb @@ -0,0 +1,5 @@ +class ProfilesController < ApplicationController + def show + @profile = Profile.find params[:id] + end +end diff --git a/app/models/profile.rb b/app/models/profile.rb index 2107e8c..33d5cc7 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -1,3 +1,7 @@ class Profile < ApplicationRecord has_many :posts + + def full_name + [first_name, last_name].map(&:presence).compact.join ' ' + end end diff --git a/app/views/profiles/show.html.erb b/app/views/profiles/show.html.erb new file mode 100644 index 0000000..ad9237e --- /dev/null +++ b/app/views/profiles/show.html.erb @@ -0,0 +1,11 @@ +

<%= @profile.full_name %>

+ +

<%= @profile.description %>

+ +<% if @profile.posts.present? %> + +<% end %> diff --git a/config/routes.rb b/config/routes.rb index cc42f6a..a03c68a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do - get 'home/show' root to: 'home#show' + + resources :profiles, only: :show end diff --git a/test/controllers/profiles_controller_test.rb b/test/controllers/profiles_controller_test.rb new file mode 100644 index 0000000..63339e9 --- /dev/null +++ b/test/controllers/profiles_controller_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class ProfilesControllerTest < ActionDispatch::IntegrationTest + test "should get show" do + get profiles_show_url + assert_response :success + end +end