How called view 'show' when id is in other controller

49 views Asked by At

I have a link_to on index refinancings

<%= link_to "View details", refinancing_path(@refinancing) %>

This refinancing_path(@refinancing) is refinancings/6 for example

My route is simple:

resources :refinancings, except: :destroy

And my controller is:

  def show
    @refinancing = Refinancing.find(params[:id])
    # THIS GET REFINANCING THROUGH HISTORIC REFINANCING
    @hist_refin = HistoricRefinancing.consult_historic_refinancing(params[:refinancing_id])
  end

This is model of Historic Refinancing

class HistoricRefinancing < ActiveRecord::Base
  belongs_to :authorization
  has_many :refinancings

  scope :consult_historic_refinancing, -> (refinancing_id) { HistoricRefinancing.where("refinancing_id = ? ", "#{refinancing_id}")  }

All I need is that in my view index when click on link_to show detail of refinancing for this authorization. I receive this error on click:

No route matches {:action=>"show", :controller=>"refinancings", :id=>nil} missing required keys: [:id]

Sure, there isn't id, but how get this? Please, help me!

UPDATE ######################################

My view show is....

<h3>Details of refinancing</h3>

<p>
  <strong>Name:</strong>
  <%= @refinancing.employee.person.name %>
</p>

<p>
  <strong>Period:</strong>
  <%= @refinancing.period.strftime("%m/%Y") %>
</p>

<p>
  <strong>Value</strong>
  <%= number_to_currency @refinancing.value %>
</p>

Just this...

1

There are 1 answers

7
Hieu Pham On BEST ANSWER

As your comment, the logic should be:

<% authotization.historic_refinancing.refinancings.each do |refinancing| %>
  <%= link_to "View details", refinancing_path(refinancing) %>
<% end %>