2016-04-08 68 views
0

我創建了一個refinanciamento,而且我的節目不正確。請教我不想要的工作方式

show.html.erb

<p> 
    <strong>Nome:</strong> 
    <%= @funcionario.pessoa.nome %> 
</p> 

<p> 
    <strong>Matrícula:</strong> 
    <%= @funcionario.matricula %> 
</p> 

當我把@ funcionario.first.pessoa.nome,它的 「工作」,但是,再回到第一個,我不想這樣,肯定的。

我的控制器:

def show 
    @funcionario = Funcionario.pesquisa_cpf(params[:pesquisa_func_cpf]).first 
    @refinanciamento = Refinanciamento.find(params[:id]) 
    end 

例如,當我註冊一個refinanciamento,我上節目的網址是:/ refinancimento/100,這refinanciamento的數值:ID:100,funcionario_id:2 我需要一個那裏顯示有這個refinanciamento的funcionario。我如何構建這個諮詢?

我的車型有:

class Refinanciamento < ActiveRecord::Base 
    belongs_to :funcionario 
(...) 

class Funcionario < ActiveRecord::Base 
    has_many :refinanciamentos 
(...) 

我只是想表明諾姆和funcionario的matricula有創建的refinanciamento。謝謝!

+0

「我只是想顯示nin和matricula of funcionario有refinanciamento創建。」您可能需要提供一些翻譯以提供給讀者上下文。 –

+0

對不起,但我的系統是葡萄牙語,因爲我不翻譯,好嗎?是「nome」和「matricula」 –

+0

我猜nome是「名稱」,你是什麼意思的「matricula」,「pesquisa_cpf」和「諮詢」? mandarula可以「註冊」; –

回答

1

首先,Rails是一個自以爲是的框架,並且假定了一些模式來促進開發人員的生活,比如從類名到屬性實現英語中的所有內容。所以,你用你的母語丟失了太多的編程(你總是可以翻譯所有東西來翻譯文本和內容,代碼應該是英文的)。

其次,正確的問題是,您在refinanciamentofuncionario之間存在關聯。如果有refinanciamentobelongs_to a funcionario,那麼當您有refinanciamento對象時,可以使用@refinanciamento.funcionario並獲取其所有數據,如nomematricula

def show 
    @refinanciamento = Refinanciamento.find(params[:id]) 
    # Here you can access funcionario's properties like 
    # @refinanciamento.funcionario.pessoa.nome 
    # @refinanciamento.funcionario.matricula 
    # etc... 
end 
相關問題