kareemgrant
2/24/2015 - 12:43 AM

index.html.erb

class UsersController < ApplicationController
  def index
    @users = User.all
  end

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

  def destroy
    @user = User.find_by_id(params[:id])
    @student.destroy
    flash[:notice] = "This user was deleted."
  end
end
<h1>Here's some info about one user:</h1>

<ul>
  <li>Id: <%= @user.id %></li>
  <li>Name: <%= @user.name %></li>
  <li>Email: <%= @user.email %></li>
  <li>Phone: <%= @user.phone %></li>
</ul>

<h3>Posts</h3>

<ul>
  <% @posts.each do |post| %>
    <li><%= post.title %></li>
  <% end %>
</ul>
class PostsController < ApplicationController
  def index
    @user = User.find_by_id(params[:user_id])
    @posts = @user.posts
  end
end

<h1>Posts for one user:</h1>
<% @posts.each do |post| %>
  <%= post.title %>
<% end %>