title: I wanna use model attribute in view Rails
body: <p>I am trying to use attribute value in model but its not working..
  I have three models:</p>
  
  <p><strong><em>models/resident.rb</em></strong></p>
  
  <pre><code>class Resident &lt; ActiveRecord::Base
    belongs_to :hostel
    has_one :user,dependent: :delete
  end
  </code></pre>
  
  <p><strong><em>models/user.rb</em></strong></p>
  
  <pre><code>class User &lt; ActiveRecord::Base
   belongs_to:resident
  end
  </code></pre>
  
  <p><strong><em>models/hostel.rb</em></strong></p>
  
  <pre><code>class Hostel &lt; ActiveRecord::Base
    has_many :residents
    has_one :rate_card,dependent: :delete
  end
  </code></pre>
  
  <p><strong>Schema</strong></p>
  
  <p><em>Resident</em></p>
  
  <pre><code>create_table "residents", force: :cascade do |t|
      t.string   "room_number"
      t.string   "roll_number"
      t.string   "name"
      t.datetime "created_at",  null: false
      t.datetime "updated_at",  null: false
      t.integer  "hostel_id"
    end
  </code></pre>
  
  <p><em>User</em></p>
  
  <pre><code>create_table "users", force: :cascade do |t|
      t.string   "roll_number"
      t.string   "email"
      t.datetime "created_at",                        null: false
      t.datetime "updated_at",                        null: false
      t.integer  "resident_id"
    end
  </code></pre>
  
  <p><em>Hostel</em></p>
  
  <pre><code>create_table "hostels", force: :cascade do |t|
      t.string   "hostel"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
    end
  </code></pre>
  
  <p>Now i want to use the hostel attribute value in <strong><em>users/show.html.erb</em></strong>
  I am able to do this :</p>
  
  <pre><code>&lt;%if @user.resident.roll_number=="101303110"%&gt;
  </code></pre>
  
  <p>if the roll number is present then returning <strong>true</strong>..
  but if is use :</p>
  
  <pre><code>&lt;%if @user.resident.hostel=="J"%&gt;
  </code></pre>
  
  <p>and if J is a hostel present in Hostel model then it is returning  <strong>false</strong>.</p>
  
  <p>But  when we put<code>&lt;%@user.resident.hostel%&gt;</code> in show.html.erb then it is showing value J. 
  How should I use related models attributes in each other view?</p>