Accessing parent scope in nested resource in Rails 3.0.9 -
i have machine model nested resource called test. linac has_many tests. test model has boolean attribute called "baseline". have nested resource called baselines, doesn't have model. meant aggregate of recent tests machine "baseline" set "true".
in machine model, have scope called energy_x
class machine < activerecord::base scope :energy_x, lambda { |x| where(:energy => x) } in baseline controller, can access named scope:
@energies.each |energy| @baseline_tests << machine.baseline_tests.energy_x(energy) end but if try access scope in view,
<%= render :partial => "baseline_test", :collection => @baseline_tests.energy_x(energy) %> i undefined method error:
undefined method `energy_x' #<array:0x007f9da7686950> i've heard shouldn't using scope in view anyway, need way sort collection @baseline_tests according parameter. there unlimited options value of parameter, doesn't make sense create instance variable in controller called @baseline_tests_1 , @baseline_tests_2. think has done in loop in view.
any suggestions?
Comments
Post a Comment