0

I'm building an ecommerce app in Rails 4. After I submit an order, I get to a thank you page. When I hit the back button, I get taken back to the order form with all data filled in, including credit card info. So if I hit submit again, a new order gets placed.

When the user hits the back button, how do I delete all form data. That would suffice because if the user enters all their information again, it's not an accidental order.

Any other recommended ways to solve this?

Here is part of the form code..

    <%= f.text_field :cardname %>
    <%= f.text_field :address %>
    <%= f.text_field :address2 %>
    <%= f.text_field :city %>
    <%= f.select(:state, options_for_select(us_states, f.object.state), {prompt: "Select"}) %>
    <%= f.text_field :zip %>

    <%= text_field_tag :card_number, nil, { :name => nil, :'data-stripe' => "number" %>
    <%= text_field_tag :card_code, nil, { :name => nil, :'data-stripe' => "cvc" } %>
    <%= select_month nil, { use_two_digit_numbers: true }, { :name => nil, :'data-stripe' => "exp-month" } %>
    <%= select_year nil, { start_year: Date.today.year, end_year: Date.today.year+10 }, { :name => nil, :'data-stripe' => "exp-year" } %>

    <%= f.submit "Confirm Order" %>

UPDATE: Based on this other question, I entered the below code in my order controller. This code gives the user some warnings so it helps. But the user can click ok on the warning dialog and go back to the order page and the info still shows up in the form. Is there a simple way to erase cache on the order form when a user hits the back button?

  before_filter :set_cache_buster

  def set_cache_buster
    response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
    response.headers["Pragma"] = "no-cache"
    response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
  end
Community
  • 1
  • 1
Moosa
  • 3,126
  • 5
  • 25
  • 45
  • which back button are you talking about ? browsers or your forms ? – Rahul Dess Nov 26 '14 at 01:03
  • http://stackoverflow.com/questions/711418/how-to-prevent-browser-page-caching-in-rails .. see if this helps. – Rahul Dess Nov 26 '14 at 01:10
  • Browsers back button. The link looks like it should solve my problem. Will try it out. – Moosa Nov 26 '14 at 01:15
  • The code in the link works to some extent. When I hit back, I get warnings. When I click ok in the dialog box asking if I should resubmit data, I get a Stripe error (which is good cos no order accidentally submitted) but when I click back again, I get back to the order page with all details filled in. Is there a way to just delete the order form in browser cache without any warnings, etc. – Moosa Nov 26 '14 at 21:06

0 Answers0