Adding a 'coupon-like' feature to a checkout process?

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 =

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       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


hmm I tried this out - but I am not sure I am doing it right. Mainly because I am trying to integrate this into the membership/upgrade view yet the coupon is related to the coupon/validate (controller,action).

I tried to plug it in to that form snippet you gave me, but it doesn't work. Any guidance towards this?


Sorry to bug you again. But I'm not sure I want to do this with ajax at the moment. Mainly because the project is using jquery as well, so how would I do this with only forms? Would it have to be two forms in a view?