Models Procedure and Option have a HABTM relationship
Model Quote builds prices on the basis of the parameters from the first two tables in a multi-step form.
Step 1 queries Procedure and a helper file (or module) extracts relevant data.
def quote_procedure
procedure = Procedure.where(['id = ?',params[:quote][:procedure_id]]).first
end
and various calculations are run, as well as identifying all related options. At this point, I want to run calculations for_each related option. However, they are not parametrised and are not stored values of table Quote. no @, no params ...
I have not found the proper syntax to process the relevant data from the options table. From helper (eventually module, as I'll have to execute the calculations):
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
However, if in the controller
@options = Option.where(['procedures_options.procedure_id = ? AND option_type_id = ?', params[:quote][:procedure_id], 1]).joins(:procedures)
I generate a result in the view with helper methods (all but the last one)
<%= (global.speed_setup_intercept + (globale.speed_setup_factor * surface)) * options.print_speed %>
But cannot manage to get it through a helper method. The offending proposition is
options.print_speed
and generates undefined method
error