title: Getting values from another table on Ruby on Rails
body: <p>I'm kind of new on Ruby on Rails and I have a little problem: 
  I have three classes (upgrade, credit_card and user), and, as a User, I need to insert my credit cards to buy an upgrade. All my classes are working properly. But the problem is that I need to get all the credit cards numbers that the user had already inserted and put them into the Upgrade.form (using a select box or anything else) as an array, so one of them can be selected. So, I wanted to bring all the credit cards information to one variable:</p>
  
  <pre><code>    class Upgrade &lt; ActiveRecord::Base
        attr_accessible :account_plan, :credit_card
        has_one :credit_card
        belongs_to :user
  
        CREDIT_CARD_GETTER = current_user.credit_card
      end
  </code></pre>
  
  <p>Then, I want to to use this on my select box. On the form page:</p>
  
  <pre><code>   &lt;div class="field"&gt;
      &lt;%= f.label "Choose your Credit Card*" %&gt;&lt;br /&gt;
      &lt;%= f.select :credit_card, #&lt;%= current_user.credit_card.number %&gt; %&gt;
  </code></pre>
  
  <p>What should I do? Is it right? Sorry I'm a newbie on ruby.
  Thanks!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>For helping, I'm updating the codes, and put them all here. I want to show the Credit Card Number as an option.</p>
  
  <p>UPGRADE index
          My Account Plans:
          
          
          Plano de Compra
          </p>
  
  <pre><code>    &lt;% @upgrades.each do |upgrade| %&gt;
      &lt;tr&gt;
      &lt;td&gt;&lt;%= upgrade.account_plan %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= link_to 'Destroy', upgrade, method: :delete, data: { confirm: 'Are you sure?' } %&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;% end %&gt;
      &lt;/table&gt;
  
      &lt;br /&gt;
  </code></pre>
  
  <p>Upgrade Model</p>
  
  <pre><code>    class Upgrade &lt; ActiveRecord::Base
      attr_accessible :account_plan, :credit_card
      belongs_to :user 
      has_many :credit_cards
      end
  </code></pre>
  
  <p>User Model</p>
  
  <pre><code>    class User &lt; ActiveRecord::Base        
      has_many :credit_cards
      has_many :upgrades
  </code></pre>
  
  <p>Credit Card form</p>
  
  <pre><code>    &lt;div class="field"&gt;
      &lt;%= f.label "Flag" %&gt;&lt;br /&gt;
      &lt;%= f.select :flag,   [['American Express', '1'],['VISA', '2'],['Dinners', '3'],   ['MasterCard', '4']] %&gt;
      &lt;/div&gt;&lt;br&gt;
      &lt;div class="field"&gt;
      &lt;%= f.label "Nome no Cartão" %&gt;&lt;br /&gt;
      &lt;%= f.text_field :name, :class =&gt; "span3"%&gt;
      &lt;/div&gt;
      &lt;div class="field"&gt;
      &lt;%= f.label "Card Number" %&gt;&lt;br /&gt;
      &lt;%= f.text_field :number, :class =&gt; "span3"%&gt;
      &lt;/div&gt;
      &lt;div class="field"&gt;
      &lt;%= f.label "Data de Validade" %&gt;&lt;br /&gt;
      &lt;%= f.text_field :date %&gt;
      &lt;/div&gt;
      &lt;div class="field"&gt;
      &lt;%= f.label "Sec. Code" %&gt;&lt;br /&gt;
      &lt;%= f.text_field :seg_cod, :class =&gt; "span1"%&gt;
      &lt;/div&gt;
      &lt;div class="actions"&gt;
      &lt;%= f.submit %&gt;
      &lt;/div&gt;
      &lt;% end %&gt;
  </code></pre>
  
  <p>Credit Card Model</p>
  
  <pre><code>    class CreditCard &lt; ActiveRecord::Base
      attr_accessible :date, :flag, :name, :number, :seg_cod
      validates_presence_of :date, :flag, :name, :number, :seg_cod, presence =&gt; true
      belongs_to :upgrade
      belongs_to :user
      end
  </code></pre>