0

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

Elton Santos
  • 571
  • 6
  • 32

1 Answers1

1

As your comment, the logic should be:

<% authotization.historic_refinancing.refinancings.each do |refinancing| %>
  <%= link_to "View details", refinancing_path(refinancing) %>
<% end %>
Hieu Pham
  • 6,577
  • 2
  • 30
  • 50
  • Sorry man, my code is in portuguese, so I translate it, and writting here I forget this... but my routes is refinancings and RefinancingsController, the error is other =( – Elton Santos May 10 '16 at 19:17
  • I see, so the clue is: @refinancing may be nil . Try to check it? – Hieu Pham May 10 '16 at 19:19
  • Yes, is nil... but I have id – Elton Santos May 10 '16 at 19:22
  • The problem is that authorization haven't refinancing_id and refinancing haven't authorization_id, but historic_refinancing have authorization_id and refinancing_id – Elton Santos May 10 '16 at 19:23
  • So it becomes simple, let me update my answer and you can take a look – Hieu Pham May 10 '16 at 19:28
  • don't work man = ( What I do? This: <% authotization.historic_refinancing.each do |refinancing| %> <%= link_to "View details", refinancing_path(refinancing) %> <% end %> But don't work. I need do each because I need iterate in authorizations, because 1 refing can have more then one authorization – Elton Santos May 10 '16 at 20:38
  • Nothing man = ( >>>> OCIError: ORA-00904: "HISTORICS_REFINANCINGS"."AUTHORIZATION_ID": identificador inválido: SELECT "HISTORICS_REFINANCINGSS".* FROM "HISTORICS_REFINANCINGS" WHERE "HISTORICS_REFINANCINGS"."AUTHORIZATION_ID" = :a1 AND ROWNUM <= 1 – Elton Santos May 11 '16 at 12:31