Im doing a model association between two models that are called Resume and Province.
Where:
class Resume < ActiveRecord::Base
has_one :province
end
and
class Province < ActiveRecord::Base
belongs_to :resume
end
at this point, everything is okay, but wh开发者_如何学JAVAen I'm listing all resumes, I want to display the province name instead the province_id.
So, whats the better way to do such thing without have to perform a select for every single record?
Maybe this association is wrong.
In the Province table I have only the name and id fields.
province - id - name
resume - name - lastname - ... - province_id
Tell me if you need more details.
Try something like this:
controller.rb
@resumes = Resume.all
in your view:
<% @resumes.each do |resume| %>
<%= resume.province.name %>
<% end %>
精彩评论