Html RoR总和问题
我的Ruby应用程序有问题。我创建了与资源(资源id)关联的用户。用户的工作时间表示资源的容量。资源表应显示资源的总容量。资源的总容量是指分配给相应资源的用户的容量之和。但是,在资源表中,每个资源显示相同的容量(所有资源的总和) 例如: 我有两个用途,每个工作8小时: 用户1:容量8,资源id 1 用户1:容量8,资源id 2 现在资源表中应该有2个资源,每个资源的容量为8。然而,与我一起,这两种资源的容量为16 以下是相应的索引文件、控制器和模型 资源索引Html RoR总和问题,html,ruby-on-rails,ruby,Html,Ruby On Rails,Ruby,我的Ruby应用程序有问题。我创建了与资源(资源id)关联的用户。用户的工作时间表示资源的容量。资源表应显示资源的总容量。资源的总容量是指分配给相应资源的用户的容量之和。但是,在资源表中,每个资源显示相同的容量(所有资源的总和) 例如: 我有两个用途,每个工作8小时: 用户1:容量8,资源id 1 用户1:容量8,资源id 2 现在资源表中应该有2个资源,每个资源的容量为8。然而,与我一起,这两种资源的容量为16 以下是相应的索引文件、控制器和模型 资源索引 <% provide(:tit
<% provide(:title, 'Ressourcen') %>
<p id="notice"><%= notice %></p>
<h1>Ressourcen</h1>
<table id="resources" class="display">
<thead>
<tr>
<th>Name</th>
<th>Gesamtkapazität</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @resources.each do |resource| %>
<tr>
<td><%= resource.name %></td>
<td><%= User.sum(:capacity, :conditions => {:resource_id => resource}) %></td>
<td><%= link_to 'Anzeigen', resource %></td>
<td><%= link_to 'Entfernen', resource, method: :delete, data: { confirm: 'Sind Sie sich sicher?' } %></td>
<% end %>
</tr>
</tbody>
</table>
雷索岑
名称
Gesamtkapazität
{:resource_id=>resource})%>
resource.model:
class Resource < ActiveRecord::Base
def resource_params
params.require(:resource).permit(:created_at, :name, :ocr, :cost, :oce)
end
validates :name, presence: true, uniqueness: true, length: {maximum: 50}
has_many :procedure_resources, :dependent => :destroy
has_many :procedures, through: :procedure_resources
has_many :users, :dependent => :destroy
end
类资源:销毁
有很多:过程,通过::过程资源
拥有多个:用户,:依赖=>:销毁
结束
资源管理员:
class ResourcesController < ApplicationController
before_action :set_resource, only: [:show, :edit, :update, :destroy]
# GET /resources
# GET /resources.json
def index
@resources = Resource.all
@procedures = Procedure.all
@project = Project.find(1)
end
def show
@resource = Resource.find(params[:id])
end
private
def set_resource
@resource = Resource.find(params[:id])
end
def resource_params
params.require(:resource).permit(:name, :oce, :oce, :cost, :ocr)
end
end
class-ResourcesController
users.model:
class User < ActiveRecord::Base
belongs_to :resource
class用户
有人知道我是如何管理它的吗?它只显示resource.index中相应资源的容量?
错误必须位于resource.index中,并包含以下行:
{:resource\u id=>resource})%>
还是
致以最良好的祝愿,
菲利普欢迎来到stackoverflow。当提出问题时,您应该发布复制或查看问题所需的最少代码。问题中的大部分代码都与问题无关,这会降低这里的人试图解决问题的可能性。请仅使用所需代码更新问题。谢谢!我已尝试删除不相关的代码:)