1
0
Fork 0

Add action ProfilesController#show

master
Alex Kotov 2 years ago
parent b86d78fac0
commit ca39eea326
  1. 5
      app/controllers/profiles_controller.rb
  2. 4
      app/models/profile.rb
  3. 11
      app/views/profiles/show.html.erb
  4. 3
      config/routes.rb
  5. 8
      test/controllers/profiles_controller_test.rb

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

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

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

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

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