Ruby on rails Rails从数据库的动态页面刷新网页视图
我的数据库中有一个动态视图。我正在使用Postgres,这是我的观点Ruby on rails Rails从数据库的动态页面刷新网页视图,ruby-on-rails,ruby,postgresql,Ruby On Rails,Ruby,Postgresql,我的数据库中有一个动态视图。我正在使用Postgres,这是我的观点 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_tim
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\consultants\u clients\u 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>
在模型内部,我有文件夹reports
,其中包含文件consultants\u clients\u task.rb
class Reports::ConsultantsClientsTasksController < ApplicationController
def index
@consultants_clients_tasks = ConsultantsClientsTask.all
end
end
module ReadOnlyModel
extend ActiveSupport::Concern
class Reports::ConsultantsClientsTask < ActiveRecord::Base
self.table_name = "consultants_clients_tasks"
end
end
当我第一次加载到页面时,一切正常,问题是当我刷新页面时,我得到了这个错误
错误很明显,因为您使用了一个错误的类名。你需要改变
@consultants_clients_tasks = ConsultantsClientsTask.all
到
@consultants_clients_tasks = ConsultantsClientsTask.all
@consultants_clients_tasks = Reports::ConsultantsClientsTask.all