I am not sure how to go about this. So far I only have my coupon model built.
Basically what I am trying to achieve is simply being able to 'use' a coupon that is created, to knock the price down on the total of the model that is handling the checkout.
I was wondering if the 'model that is handling the checkout' even needs to be related to the coupon. I was thinking I could simply do @coupon = Coupon.new
Another thing is, I am not sure how to set up the form functionality of being able to update something on the screen. Maybe ajax?
Imagine something like this on the browser:
Buy so and so : $15
Total: $15
(Form to enter billing address)
(coupon field) (update) <--- how would this work? Basically have the coupon if valid, change Total.
Reset / Checkout
I tried creating a method like this in the coupon model but I am coding pretty blind - so let me know if there is a better way to tackle this.
[code=ruby] def discount coupon = Coupon.find(params[:code]) if coupon.active? total = total * coupon / 100 else flash[:notice] = "Invalid Coupon" end end[/code] How would I even run this? Could I do it through the form? <%= text_field :coupon, :discount %>
Thanks for the help, Daniel