title: Getting around a NoMethodError in Users#show
body: <p>My app has three types of profiles:</p>
  
  <ul>
  <li>Provider </li>
  <li>Professional </li>
  <li>&amp; Seeker</li>
  </ul>
  
  <p>I display these profiles with a User index page to view all profiles.</p>
  
  <p>The problem i am having is that I can see all profiles on the index page but cannot access them unless signed in as that type of profile.</p>
  
  <p>Professional user profiles can see all profiles but can only access professional profiles.</p>
  
  <p>How can I get around this? I can see why I get a NoMethodError in Users#show error as per the below <code>show.html.erb</code> code; however, I can't quite figure out how I can get around it.</p>
  
  <p>Thank you in advance.</p>
  
  <pre><code>#show.html.erb
  
  &lt;div class="row"&gt;
  &lt;% if current_user.provider %&gt;
      &lt;div class="col-md-3 text-center"&gt;
          &lt;%= image_tag @user.provider.avatar.url %&gt;
      &lt;/div&gt;
      &lt;div class="col-md-6"&gt;
          &lt;h1&gt;&lt;%= @user.provider.company_name %&gt;&lt;/h1&gt;
          &lt;h3&gt;Provider&lt;/h3&gt;
          &lt;div class="well provider-description"&gt;
              &lt;h3&gt;Description&lt;/h3&gt;
              &lt;%= @user.provider.description %&gt;
          &lt;/div&gt;
          &lt;div class="well provider-contact"&gt;
              &lt;h3&gt;Contact Information&lt;/h3&gt;
              &lt;%= @user.provider.company_number %&gt;
              &lt;%= @user.provider.company_email %&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  
  &lt;% elsif current_user.professional %&gt;
      &lt;div class="col-md-3 text-center"&gt;
          &lt;%= image_tag @user.professional.avatar.url %&gt;
      &lt;/div&gt;
      &lt;div class="col-md-6"&gt;
          &lt;h1&gt;&lt;%= @user.professional.first_name %&gt; &lt;%= @user.professional.last_name %&gt;&lt;/h1&gt;
          &lt;h3&gt;Professional&lt;/h3&gt;
          &lt;div class="well professional-description"&gt;
              &lt;h3&gt;Description&lt;/h3&gt;
              &lt;%= @user.professional.description %&gt;
          &lt;/div&gt;
          &lt;div class="well professional-contact"&gt;
              &lt;h3&gt;Contact Information&lt;/h3&gt;
              &lt;%= @user.professional.phone_number %&gt;
              &lt;%= @user.professional.contact_email %&gt;
          &lt;/div&gt;
      &lt;/div&gt; 
  
  &lt;% elsif current_user.seeker %&gt; 
      &lt;div class="col-md-3 text-center"&gt;
          &lt;%= image_tag @user.seeker.avatar.url %&gt;
      &lt;/div&gt;
      &lt;div class="col-md-6"&gt;
          &lt;h1&gt;&lt;%= @user.seeker.first_name %&gt; &lt;%= @user.seeker.last_name %&gt;&lt;/h1&gt;
          &lt;h3&gt;Seeker&lt;/h3&gt;  
            &lt;div class="well seeker-description"&gt;
                &lt;h3&gt;Description&lt;/h3&gt;
                &lt;%= @user.seeker.description %&gt;
            &lt;/div&gt;
            &lt;div class="well seeker-contact"&gt;
              &lt;h3&gt;Contact Information&lt;/h3&gt;  
              &lt;%= @user.seeker.phone_number %&gt;&lt;br/&gt;
              &lt;%= @user.seeker.contact_email %&gt;&lt;br/&gt;
           &lt;/div&gt;
      &lt;/div&gt;
  &lt;% end %&gt; 
  </code></pre>
  
  <p></p>
  
  <pre><code>#index.html.erb
      &lt;div class="row"&gt;
  &lt;div class="col-md-8 col-md-offset-2"&gt;
  &lt;ul class="list-unstyled"&gt;
    &lt;% @users.each do |user| %&gt;
      &lt;% if user.provider %&gt;
      &lt;li&gt;
        &lt;div class="well row &lt;%= cycle('white-bg', '') %&gt;"&gt;
          &lt;div class="col-sm-4 text-center"&gt;
            &lt;% if user.provider.avatar %&gt;
              &lt;%= link_to user do %&gt;
                &lt;%= image_tag user.provider.avatar.url(:thumb), class: 'user-index-avatar' %&gt;
              &lt;% end %&gt;
            &lt;% end %&gt;
          &lt;/div&gt;
          &lt;div&gt;
            &lt;%= link_to user do %&gt;
              &lt;h2&gt;&lt;%= user.provider.company_name %&gt;&lt;/h2&gt;
            &lt;% end %&gt;
            &lt;p&gt;&lt;%= user.provider.description %&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/li&gt;
      &lt;% elsif user.professional %&gt;
      &lt;li&gt;
        &lt;div class="well row &lt;%= cycle('white-bg', '') %&gt;"&gt;
          &lt;div class="col-sm-4 text-center"&gt;
            &lt;% if user.professional.avatar %&gt;
              &lt;%= link_to user do %&gt;
                &lt;%= image_tag user.professional.avatar.url(:thumb), class: 'user-index-avatar' %&gt;
              &lt;% end %&gt;
            &lt;% end %&gt;
          &lt;/div&gt;
          &lt;div&gt;
            &lt;%= link_to user do %&gt;
              &lt;h2&gt;&lt;%= user.professional.first_name %&gt;&lt;%= user.professional.last_name %&gt;&lt;/h2&gt;
            &lt;% end %&gt;
            &lt;p&gt;&lt;%= user.professional.description %&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/li&gt;
      &lt;% elsif user.seeker %&gt;
      &lt;li&gt;
        &lt;div class="well row &lt;%= cycle('white-bg', '') %&gt;"&gt;
          &lt;div class="col-sm-4 text-center"&gt;
            &lt;% if user.seeker.avatar %&gt;
              &lt;%= link_to user do %&gt;
                &lt;%= image_tag user.seeker.avatar.url(:thumb), class: 'user-index-avatar' %&gt;
              &lt;% end %&gt;
            &lt;% end %&gt;
          &lt;/div&gt;
          &lt;div&gt;
            &lt;%= link_to user do %&gt;
              &lt;h2&gt;&lt;%= user.seeker.first_name %&gt;&lt;%= user.seeker.last_name %&gt;&lt;/h2&gt;
            &lt;% end %&gt;
            &lt;p&gt;&lt;%= user.seeker.description %&gt;
          &lt;/div&gt;            
        &lt;/div&gt;
      &lt;/li&gt;
      &lt;% end %&gt;
    &lt;% end %&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>
  </p>
  
  <pre><code>#users_controller
  class UsersController &lt; ApplicationController
  before_action :authenticate_user!  
  
    def show
      @user = User.find( params[:id] )
    end
  
    def index
      @users = User.includes(:provider, :professional, :seeker)
    end
  
  
  end
  
  #user.rb (model)
   class User &lt; ActiveRecord::Base
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
       :recoverable, :rememberable, :trackable, :validatable
  
    has_one :provider
    has_one :professional
    has_one :seeker
    end
  </code></pre>