Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 Rails在另一个控制器中显示数据_Ruby On Rails 4_Controller_Relationship_Custom Routes - Fatal编程技术网

Ruby on rails 4 Rails在另一个控制器中显示数据

Ruby on rails 4 Rails在另一个控制器中显示数据,ruby-on-rails-4,controller,relationship,custom-routes,Ruby On Rails 4,Controller,Relationship,Custom Routes,我需要在我的中央控制器中显示其他控制器的数据 中央=患者\控制器.rb 其他=重量\u控制器.rb 控制器具有如下关系 型号: patient.rb=有许多:体重 weight.rb=属于:患者 我只需要在视图中显示一名患者的体重 我试试这个: 创建路线=获取“比索/:id/”,到:“患者#体重” 在控制器中创建def患者= def weights end 在此之前,我尝试调用以下视图: <%= @patient.weight %> 但是我无法显示任何结果,任何人

我需要在我的中央控制器中显示其他控制器的数据
中央=患者\控制器.rb
其他=重量\u控制器.rb
控制器具有如下关系
型号:
patient.rb=有许多:体重
weight.rb=属于:患者

我只需要在视图中显示一名患者的体重
我试试这个:
创建路线=获取“比索/:id/”,到:“患者#体重”
在控制器中创建def患者=

def weights  
end  
在此之前,我尝试调用以下视图:

<%= @patient.weight %>  


但是我无法显示任何结果,任何人都可以帮助我。

我找到了显示数据的解决方案
在病人控制器我做这个

对照组患者

  def weight  
  end  
并创建了view weight.html.slim

 p#notice = notice
    .row
      p
      table
thead
tr
    th Nome:
    th Sexo:
    th Data de nascimento:
    th Idade:


       tbody
  tr
    td = @patient.name
    td = @patient.sex.name
    td = @patient.born
    td = ((Date.today - @patient.born) / 365).to_i
      p

      table
thead
  tr
    th Plano:
    th Senha de internação:
    th Admimissão:
    th Altura:
tbody
  tr
    td = @patient.plan.name
    td = @patient.pass
    td = @patient.admission
    - if @patient.weight.first.inch != nil
        td = @patient.weight.first.inch
    - else
        td = 'Paciente sem altura registrada'
      p
      table
        thead
          tr
            th Data
            th Peso
            th IMC:

        strong pesos:
tbody
  - @patient.weight.each do |m|
    tr
      - if m.date != nil
          td = m.date
      - else
          td = 'Sem pesos registrados'

      - if m.weight != nil
          td  = m.weight
      - else
          td  = 'sem peso registrado'

      - if @patient.weight.first.inch != nil
          td  = (m.weight / (@patient.weight.first.inch**2).to_f).round(2)
      - else
          td  = 'sem dados para este calculo'

      br´
在index.html.erb中

<td><a href="/peso/<%= patient.id %>" target="_blank">Relatorio</a></td>  

并解决了我的问题

您是否能够执行其他crud操作?
get 'peso/:id/', to: 'patients#weight'