title: How to show username from User model to the index view of Quote controller?
body: <p>When I create a quote it asks for the quote body, author and user id, user and quotes are associated but I want to show the username of the user with the user ID that someone puts when a quote is create. So if a user has the username "shanks" and his ID is 4 and when user creates a quote and in the text field of user_id he enters 4... I want in the index view of Quotes controller to show the username of the user with that id.</p>
  
  <pre><code>def index
      @quote = Quote.new
      @quotes = Quote.order(created_at: :desc).all
      @user = User.new
  end
  </code></pre>
  
  <p>view:</p>
  
  <pre><code>&lt;!-- form to add a Quote --&gt;
  &lt;div class="create-quote"&gt;
  &lt;%= form_for @quote do |f| %&gt;
  &lt;%= f.label :quotetext %&gt;&lt;br&gt;
  &lt;%= f.text_field :quotetext %&gt;&lt;br&gt;
  
  &lt;%= f.label :author %&gt;&lt;br&gt;
  &lt;%= f.text_field :author %&gt;&lt;br&gt;
  
  &lt;%= f.label :user_id %&gt;&lt;br&gt;
  &lt;%= f.text_field :user_id %&gt;&lt;br&gt;
  &lt;%= f.submit "Add quote" %&gt;
  &lt;% end %&gt;
  &lt;/div&gt;
  &lt;!-- All quotes here --&gt;
  &lt;% @quotes.each do |quote| %&gt;
  &lt;blockquote&gt;
      &lt;p&gt;
          &lt;%= quote.quotetext %&gt;
      &lt;/p&gt;
      &lt;footer&gt;
          &lt;cite&gt; 
              &lt;%= quote.author %&gt;&lt;br&gt;
          &lt;/cite&gt;
          &lt;p&gt;Posted by: &lt;%= @user.username %&gt; &lt;/p&gt; &lt;!-- this --&gt;
      &lt;%= link_to "Delete quote", quote_path(quote), method: :delete, data: { confirm: "Are you sure you want to delete this beautiful quote?"}     %&gt;
      &lt;/footer&gt;
  &lt;/blockquote&gt;
  &lt;%= quote.like %&gt;&lt;/br&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>user model:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
  has_many :quotes
  validates :username ,presence: true
  validates :password ,presence: true
  end
  </code></pre>
  
  <p>quote model:</p>
  
  <pre><code>class Quote &lt; ActiveRecord::Base
  belongs_to :user
  validates :quotetext, presence: true,
      length: { minimum: 5}
  validates :author, presence: true
  end
  </code></pre>