1. Displaying user info

We're almost towards the end of creating this app! In our last part, we're going to build out a user profile page, just like Instagram does.

Let's go ahead and create our show.html.erb in our app/views/users. This is going to be our profile page for users.

In our users_controller.rb, let's add in the show method:

def show
  @user = User.find(params[:id])
end

We can now use @user to display information about the user in our show.html.erb that we just created.

In our show.html.erb, let's just list out the user's email username.

<%= @user.email.split('@').first %>

Next, let's loop through the user's posts and display it on the page:

<%= @user.email.split('@').first %>

<% @user.posts.each do |post| %>
  <%= image_tag post.photo %>
<% end %>

Let's also add the number of posts the user has. We can do something fancy like this:

<%= pluralize(@user.posts.count, 'post') %>

This is one example of a super handy Rails helper method. It pluralizes "post" to "posts" if @user.posts.count is plural, and displays "post" if @user.posts.count is singular.

<%= @user.email.split('@').first %>

<%= pluralize(@user.posts.count, 'post') %>

<% @user.posts.each do |post| %>
  <%= image_tag post.photo, class: 'mb-4' %>
<% end %>

Awesome! In the next section, we're going to style everything all at once so that it looks exactly like Instagram!

Lesson list