2014-10-15 4 views
0

내가 내 중앙 컨트롤러 = patients_controller.rb
중앙에서 다른 컨트롤러의 데이터를 표시 할 필요가 다른 컨트롤러에 데이터를 표시합니다. RB = has_many : 무게
weight.rb = belongs_to : 환자레일 <br> 기타 = weights_controller.rb <br> 컨트롤러이 <br> 모형과 같은 관계가

은 내가 이것을 시도보기
한 환자의 가중치를 표시해야합니다 :

:이 전에

def weights 
end 

내가보기이에 전화를 시도 = '환자 # 무게'
컨트롤러 환자의 DEF를 만들 :에, '아이디/페소 /' 는 = 경로를 생성 수

<%= @patient.weight %> 

하지만 아무도 나를 도와 줄 수있는 결과가 없습니다.

+0

당신이 다른 침전물 작업을 수행 할 수 있습니까 내 문제 해결? –

답변

1

나는 내가 컨트롤러 환자에서이

을 솔루션은 데이터를 환자 컨트롤러
을 보여 발견

def weight 
    end 

그리고 만들어보기 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´ 

및 in index.html.erb

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

get 'peso/:id/', to: 'patients#weight' 

에서

그리고는

관련 문제