2013-06-20 4 views
-1

reports.rb에서 출력 format.html하는레일 컨트롤러

def method 
    if self.name == "Maintenance History" 
    'maintenance_history' 
    elsif self.name == "Outstanding Maintenance" 
    'outstanding_maintenance' 
    elsif self.name == "Idle Time Report" 
    'idle_time_report' 
    end 
end 

def maintenance_history 
    maintenance_history.where(....) 
end 

def outstanding_maintenance 
    outstanding_maintenance.where(....) 
end 

def idle_time_report 
    idle_time_report.where(....) 
end 

reports_controller

def show 
    @report = Report.find(params[:id]) 

    respond_to do |format| 
     format.html # show.html.erb 

나는 HTML을 포맷하고 싶은

= render @report.method, :report => @report 

show.html.haml 다음 태그가있는 내보기의 표 %table.table.datatable#datatable

이 : 내가 제대로 문제를 이해한다면

%table.table.datatable#datatable 
    = render @report.method, :report => @report 

작동하지 않습니다 ...

+1

'# datatable'을 (를) 타겟팅하는 스타일 시트에 규칙 집합을 추가 하시겠습니까? – numbers1311407

+0

보기에서 내 보고서를 어떻게 표시하는지보십시오. 나는 단순히 컨트롤러 쇼라고 부른다. 여러 보고서가 있기 때문에 즉석에서 작성해야하지만 정렬이 가능하도록 표에 datatable css 태그를 추가해야합니다. – Bruno

+0

'format.html' 인수없이'render '를 호출하십시오 show " . 평상시처럼 스타일을 추가하십시오. – jokklan

답변

0

, 그것은 다른 테이블 보고서에 따라 다른 스타일을 요구하는이다. 컨트롤러에서 보고서의 이름을 사용하여 범위를 결정하는 것처럼보기에서 보고서의 일부 특성을 사용하여 HTML에 클래스 또는 다른 식별 특성을 추가 할 수 있습니다. 당신은 테이블이나 경계를 구분하는 것을 사용할 수,보기에 그런

# some helper for the reports 
module ReportsHelper 

    # the `method` method from your controller, migrated to a helper 
    def report_table_class(report) 
    if report.name == "Maintenance History" 
     'maintenance_history' 
    elsif report.name == "Outstanding Maintenance" 
     'outstanding_maintenance' 
    elsif report.name == "Idle Time Report" 
     'idle_time_report' 
    end 
    end 
end 

:

간단한 예를 들어, 당신처럼, 당신의 method 컨트롤러 메소드와 같은 정확히보기 에 대한 도우미를 만들 수 있습니다 당신의 CSS에 마지막으로

%table#datatable{:class => ['table', 'datatable', report_table_class(@report)]} 

과 : 당신이 당신의 스타일 선택의 대상으로 사용할 수있는 부모 요소

table.maintenance_history { 
    // style accordingly 
} 

table.idle_time_report { 
    // style accordingly 
}