2016-04-16 13 views
1

データベースに動的ビューがあります。私はPostgresのを使用していますが、これは私が持っているRailsはデータベースからページのWebビューを動的から更新します

CREATE VIEW CONSULTANTS_CLIENTS_TASKS AS 
SELECT 
    concat_ws(' ', consultants.first_name, consultants.last_name) as consultant_name, 
    clients.name as client_name, 
    tasks.name as task_name, 
    tasks.init_time::date as task_date, 
    EXTRACT (epoch FROM tasks.finish_time - tasks.init_time)/3600 as task_duration, 
    consultants_select.consultant_cost_per_hour * (EXTRACT (epoch FROM tasks.finish_time - tasks.init_time))/3600 as consultant_cost, 
    clients_select.client_amount_per_hour * (EXTRACT (epoch FROM tasks.finish_time - tasks.init_time))/3600 as client_amount, 
    task_related_costs_per_hour * (EXTRACT (epoch FROM tasks.finish_time - tasks.init_time))/3600 as task_cost_related 
FROM consultants 
INNER JOIN tasks ON consultants.id = tasks.consultant_id 
INNER JOIN clients ON tasks.client_id = clients.id 
INNER JOIN 
    (SELECT 
     consultants.id as consultant_id, 
     salaries.payment/(extract(epoch from sum(tasks.finish_time - tasks.init_time))/3600) as consultant_cost_per_hour 
    FROM consultants 
     INNER JOIN tasks ON consultants.id = tasks.consultant_id 
     INNER JOIN salaries ON consultants.id = salaries.consultant_id 
    GROUP BY consultants.id, to_char(salaries.payment_date, 'yyyy-mm'), salaries.payment 
    ORDER BY consultant_id) AS consultants_select ON consultants.id = consultants_select.consultant_id 
INNER JOIN 
    (SELECT 
    clients.id as client_id, 
    amount_client_month.amount_client/worked_client_month.worked_hours as client_amount_per_hour 
    FROM 
     (SELECT 
        clients.id as client_id, 
        to_char(purchases.date, 'yyyy-mm') as client_year_month, 
        SUM(products.price) as amount_client 
      FROM clients 
       INNER JOIN purchases ON purchases.client_id = clients.id 
       INNER JOIN products ON purchases.product_id = products.id 
      GROUP BY clients.id, to_char(purchases.date, 'yyyy-mm') 
      ORDER BY clients.id) AS amount_client_month 
    INNER JOIN 
     (SELECT 
      clients.id as client_id, 
      to_char(tasks.init_time::date, 'yyyy-mm') as month, 
      SUM(extract(epoch from (tasks.finish_time - tasks.init_time)))/3600 as worked_hours 
     FROM tasks 
      INNER JOIN clients ON clients.id = tasks.client_id 
     GROUP BY clients.id, to_char(tasks.init_time::date, 'yyyy-mm')) as worked_client_month 
    ON amount_client_month.client_id = worked_client_month.client_id 
    INNER JOIN clients ON worked_client_month.client_id = clients.id) AS clients_select ON clients.id = clients_select.client_id 
INNER JOIN 
    (SELECT 
     tasks.id as task_id, 
     SUM(costs.amount) as task_related_costs_per_hour 
    FROM costs 
    INNER JOIN task_costs ON costs.id = task_costs.cost_id 
    INNER JOIN tasks ON task_costs.task_id = tasks.id 
    GROUP BY tasks.id) AS tasks_select ON tasks.id = tasks_select.task_id; 

インサイドビュー、フォルダ、私は、ファイルとフォルダのコールreportsを持ってreports\consultants_clients_tasks

<h1>Report: ConsultantsClientsTasks</h1> 

<table class="table"> 
    <thead> 
    <tr> 
     <th>consultant_name</th> 
     <th>client_name</th> 
     <th>task_name</th> 
     <th>task_date</th> 
     <th>task_duration</th> 
     <th>consultant_cost</th> 
     <th>client_amount</th> 
     <th>task_cost_related</th> 
     <th colspan="3"></th> 
    </tr> 
    </thead> 

    <tbody> 
    <% @consultants_clients_tasks.each do |co| %> 
     <tr> 
     <td><%= co.consultant_name %></td> 
     <td><%= co.client_name %></td> 
     <td><%= co.task_name %></td> 
     <td><%= co.task_date %></td> 
     <td><%= co.task_duration %></td> 
     <td><%= co.consultant_cost %></td> 
     <td><%= co.client_amount %></td> 
     <td><%= co.task_cost_related %></td> 
     </tr> 
    <% end %> 
    </tbody> 
</table> 

内部コントローラconsultants_clients_tasks_controller.rb

インサイド
class Reports::ConsultantsClientsTasksController < ApplicationController 
    def index 
    @consultants_clients_tasks = ConsultantsClientsTask.all 
    end 
end 

私の見解でありますモデルファイルconsultants_clients_task.rb

と私は、フォルダ reportsがありますの
module ReadOnlyModel 
    extend ActiveSupport::Concern 
    class Reports::ConsultantsClientsTask < ActiveRecord::Base 
    self.table_name = "consultants_clients_tasks" 
    end 
end 

とルートで ファイルは、私はページを更新するとき、私はこのエラーを取得する私はすべてが正常に動作しますページにロードする最初の時間は、問題がある

namespace :reports do 
    get 'consultants_clients_tasks/index' 
end 

を追加

enter image description here

答えて

2

間違ったクラス名を使用しているため、このエラーは明らかです。あなたは

@consultants_clients_tasks = Reports::ConsultantsClientsTask.all 

@consultants_clients_tasks = ConsultantsClientsTask.all 

+0

を変更する必要があるそれは働いていた、あなたの答えをありがとう! – agusgambina

関連する問題