Add action ProfilesController#show
This commit is contained in:
parent
b86d78fac0
commit
ca39eea326
5 changed files with 30 additions and 1 deletions
5
app/controllers/profiles_controller.rb
Normal file
5
app/controllers/profiles_controller.rb
Normal file
|
@ -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
|
||||
|
|
11
app/views/profiles/show.html.erb
Normal file
11
app/views/profiles/show.html.erb
Normal 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 %>
|
|
@ -1,4 +1,5 @@
|
|||
Rails.application.routes.draw do
|
||||
get 'home/show'
|
||||
root to: 'home#show'
|
||||
|
||||
resources :profiles, only: :show
|
||||
end
|
||||
|
|
8
test/controllers/profiles_controller_test.rb
Normal file
8
test/controllers/profiles_controller_test.rb
Normal 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
|
Reference in a new issue