【发布时间】:2016-05-10 19:03:11
【问题描述】:
我有一个关于 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}") }
我只需要在我的视图索引中单击链接_显示此授权的再融资详细信息。 我在点击时收到此错误:
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>
就这个……
【问题讨论】:
-
您能详细更新一下您的观点吗?您定义视图的方式似乎有一个错误!
-
听起来您可能正在尝试链接到未保存的对象(那些具有 nil id)
-
使用 rake 路由正确检查路由
标签: ruby-on-rails ruby-on-rails-4 routes relationship rails-4-2-1