我有2個車型,車和註冊。軌道3與2個表之間的連接
class Car < ActiveRecord::Base
belongs_to :Registration
end
class Registration < ActiveRecord::Base
has_many :cars, :dependent => :destroy
accepts_nested_attributes_for :cars, :reject_if => lambda { |a| a[:content].blank? }, :allow_destroy => true
end
在CarsController:
def index
@cars = Car.all
@cars2 = Car.all(:joins => :Registration)
end
鑑於:
<% @cars.each do |car| %>
<tr>
<td><%= car.twitter %></td>
<td><%= car.facebook %></td>
<td>
<% @cars2.Registration.each do |h| %> #here is my problem
<%= h.email %>
<% end %>
</td>
</tr>
<% end %>
這是我的車的說法。我正在嘗試打印每個車主的電子郵件。電子郵件在表註冊(模型註冊)。我不知道如何查詢數據庫,我想從表註冊的電子郵件,當列registration_id在表汽車 == id表的列註冊...
所以我想問你,如果你有一個提示,該怎麼辦?
該死的,這麼愚蠢的錯誤.. 。 – user1946705 2011-06-12 13:18:40