I'm learning rails 4 and i'd like to know how to display in a show action an attribute coming from another model.
For information, a Deal belongs_to a business_line and a business_line has many deals.
Here is the show action for the deal controller. I'd like to display the name of the linked business_line (instead of the ID, which is stored in the Deal table) :
<div class = 'container'>
<h1> <%= @deal.name %> </h1>
<p> <%= @deal.bank_id %> </p>
<p> <%= business_line.name %> </p>
<%= link_to 'Home', root_path %>
<%= link_to 'Edit', edit_deal_path %>
<%= link_to 'Delete', deal_path(@deal), method: :delete, data: {confirm: 'Are you sure?'} %>
</div>
Here is my Deal controller :
class DealsController < ApplicationController
before_action :find_deal, only: [:show, :edit, :update, :destroy]
def show
@deal.business_line_id = @business_line.id
end
private
def deals_params
params.require(:deal).permit(:name, :bank_id, :business_line_id)
end
def find_deal
@deal = Deal.find(params[:id])
end
end
What do i have to put into my Deal controller to be able to call the business_line.name in my Deal view?
Many thanks :)