模型程序和选项具有 HABTM 关系
模型报价基于前两个表中的参数以多步形式构建价格。
第 1 步查询过程和帮助文件(或模块)提取相关数据。
def quote_procedure
procedure = Procedure.where(['id = ?',params[:quote][:procedure_id]]).first
end
并运行各种计算,并识别所有相关选项。此时,我想为_each 相关选项运行计算。但是,它们没有参数化,也不是 Quote 表的存储值。没有@,没有参数...
我还没有找到合适的语法来处理选项表中的相关数据。从助手(最终模块,因为我必须执行计算):
def quote_option
option = Option.where(['id = ?', self.id])
end
def my_calculation
(quote_option.sum_operational_costs / quote_option.procedure_speed) * params[:quote][:quantity]
end
但是,如果在控制器中
@options = Option.where(['procedures_options.procedure_id = ? AND option_type_id = ?', params[:quote][:procedure_id], 1]).joins(:procedures)
我使用辅助方法在视图中生成结果(除了最后一个)
<%= (global.speed_setup_intercept + (globale.speed_setup_factor * surface)) * options.print_speed %>
但无法通过辅助方法获得它。有问题的提议是
options.print_speed
并产生undefined method
错误