maths not working (can't get this)

I've got a few problems with this...Hopefully it's cleaer what I'm trying to do (work out and display two prices, one discounted / one full). Be grateful for answers...

The total price and discounted price are not calculated correctly and the duration is not coming through to the output page.

It's basically impossible to read this because there are almost more commented out lines than actual lines. That said you're checking whether params[:course][:course_duration] is empty but then you're using params[:course][:duration] instead.

Fred

Frederick Cheung wrote:

I've got a few problems with this...Hopefully it's cleaer what I'm trying to do (work out and display two prices, one discounted / one full). Be grateful for answers...

It's basically impossible to read this because there are almost more commented out lines than actual lines. That said you're checking whether params[:course][:course_duration] is empty but then you're using params[:course][:duration] instead.

Fred

You got it thanks...

Now I've decided I want to access factor in my view...

but it's blank when i try <br>Factor: <%= @course.factor %>

here's my model....

class Course < ActiveRecord::Base

  has_one :enquiry

  attr_accessor :duration_in_weeks   attr_reader :factor

  def self.all_courses     find(:all)   end

  def self.active_courses     # find(:all)     # find(:all, :conditions => ["active = ?", true], :order => 'created_at DESC', :limit => 5)     find(:all, :conditions => {:archive => false}, :order => 'display_order ASC', :limit => 100)   end

  def self.old_courses     # find(:all)     # find(:all, :conditions => ["active = ?", true], :order => 'created_at DESC', :limit => 5)     find(:all, :conditions => {:archive => true}, :order => 'created_at DESC', :limit => 100)   end

  def discounted_price     @factor = case @duration_in_weeks     when 1..4       1.0     when 5..12       0.9     when 13..24       0.8     when 25..47       0.7     else # from 48 and up       0.6     end

    total_price * @factor

  end

  def total_price     (@duration_in_weeks * price_per_week) + registration_fee   end

  def duration_in_weeks=(duration_in_weeks)     @duration_in_weeks = duration_in_weeks.to_i   end

end