我是ruby的初学者,我的代码正在关注
class DepensesController < ApplicationController
before_action :set_depense, only: [:show, :edit, :update, :destroy]
# GET /depenses
# GET /depenses.json
def index
@structure = Structure.all
@structure.each do |structure|
#request 1 for each structure spend
@show_depense = Depense.where(structure_id: structure.id)
end
#request 2 for categories
@groupes = Groupe.all.select { |m| m.parent_id == nil || m.parent_id =="" }
end
end
我的第一个请求允许我显示由我所在的结构执行的费用,并且一切顺利
我的第二个显示所有类别的费用,每个费用都在一个类别中。
我的问题是在其他结构中创建的类别在我的家中显示我想要避免的内容......我的意图是仅显示我的结构创建类别和费用
从查询1开始,我认为与查询2结合使用的是由登录用户所在的结构创建的类别。 我有以下查询:
@groups = Group.all.select ((| m | m.parent_id == nil || m.parent_id == "") AND (structure_id: structure.id))
它不起作用,我不知道如何去做它
我指定类别和结构的 id在表格费用中是外键
你可以帮帮我吗?提前谢谢你