当 id 在其他控制器中时如何调用视图 'show'

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

我有 link_to index 再融资

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

这个 refinancing_path(@refinancing) 例如 refinancings/6

我的路线很简单:

resources :refinancings, except: :destroy

我的控制器是:

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

这是历史再融资模型

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

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

我只需要在单击 link_to 时在我的视图索引中显示此授权的再融资详细信息。 我在点击时收到此错误:

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

当然,没有 id,但是怎么得到这个?请帮帮我!

更新######################################

我的观点是....

<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>

就是这个...

作为你的评论,逻辑应该是:

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