请教我不想要的工作方式

请教我不想要的工作方式

问题描述:

我创建了一个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可以“注册”; –

首先,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