0

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

Baldrick
  • 23,882
  • 6
  • 74
  • 79
Jerome
  • 5,583
  • 3
  • 33
  • 76
  • Check the class of `options`, it may not be the type you expect (at least it does not have a method `print_speed`) – Baldrick Jul 18 '13 at 09:54
  • the class is ActiveRecord::Base. The class has variable print_speed; the fact is I can run the calculation from the view <%= (global.speed_setup_intercept + (globale.speed_setup_factor * surface)) * options.print_speed %> but I cannot call the variable in the helper (it is not stored, nor is it a param at this point) – Jerome Jul 18 '13 at 22:20
  • My error. I was only looking at the params data in debugging. The step handles only parameters of that step, whereas the session holds parameter data from each step. – Jerome Jul 21 '13 at 10:30

0 Answers0