1
0
Fork 0

Add action ProfilesController#show

This commit is contained in:
Alex Kotov 2021-03-10 14:40:17 +05:00
parent b86d78fac0
commit ca39eea326
5 changed files with 30 additions and 1 deletions

View file

@ -0,0 +1,5 @@
class ProfilesController < ApplicationController
def show
@profile = Profile.find params[:id]
end
end

View file

@ -1,3 +1,7 @@
class Profile < ApplicationRecord
has_many :posts
def full_name
[first_name, last_name].map(&:presence).compact.join ' '
end
end

View file

@ -0,0 +1,11 @@
<h1><%= @profile.full_name %></h1>
<p><%= @profile.description %></p>
<% if @profile.posts.present? %>
<ul>
<% @profile.posts.each do |post| %>
<li><%= post.text %></li>
<% end %>
</ul>
<% end %>

View file

@ -1,4 +1,5 @@
Rails.application.routes.draw do
get 'home/show'
root to: 'home#show'
resources :profiles, only: :show
end

View file

@ -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