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

时间:2016-05-10 19:03:12

标签: ruby-on-rails ruby-on-rails-4 routes relationship rails-4-2-1

我在索引 refinancings

上有一个link_to
<%= 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]

当然,没有身份证,但是如何得到这个?拜托,帮助我!

更新###################################### < / p>

我的观点是......

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

就是这个......

1 个答案:

答案 0 :(得分:1)

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

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