0

I am not going into to many details because this has happened with multiple models.

I have a rails 3 application. On occasion, when I use the create function via browser I am greeted with 2 of whatever I was trying to create.

Am I missing a common issue or should I start adding 'uniq' to all of my models?

Brian Petro
  • 1,577
  • 16
  • 32
  • 1
    I've never seen this behavior. I think you'd be better off finding the root cause than sledgehammering uniq onto models that don't warrant it. Are you sure you're not double-clicking a submit button or something? Check your controller logs and see if two requests are coming in. Could be something weird like an AJAX request and a non-AJAX request firing due to JavaScript wonkiness. Could be that hitting enter in a field is triggering submit, and then you're also clicking submit before the page refreshes. – Jim Stewart Jan 24 '13 at 19:32
  • I am fairly confident my javascript isn't to wonkie. On that note, how should I prevent double clicks? If I manage to double click than I am certain it will become a nuisance to users. – Brian Petro Jan 24 '13 at 19:59
  • 1
    You're not supposed to double-click things on a web page. I would strongly urge you not to handle double-clicks at all, but if you must, check out http://stackoverflow.com/questions/5497073/how-to-differentiate-single-click-event-and-double-click-event for some ideas on handling it. – Jim Stewart Jan 24 '13 at 20:03
  • I am probably going to look into disabling the button after the initial click. Something like $('button').onClick().hide(). Besides not handling them at all, how does that solution sound? – Brian Petro Jan 24 '13 at 20:07
  • 1
    Not a bad idea if the intention on the first click is to navigate off the page, and if you just want to prevent a double-click from triggering a second request in the interim. I feel like there ought to be a better way to handle this but I can't think of one offhand. – Jim Stewart Jan 24 '13 at 20:09
  • Instead of hiding the button one could disable it on click or form submission with the `:disabled_with => 'Some Text'` option on the [submit tag helper](http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-submit_tag). – Thomas Klemm Jan 24 '13 at 20:32

1 Answers1

0

Using JavaScript to prevent multiple clicks.

"I am probably going to look into disabling the button after the initial click. Something like

$('button').onClick().hide().

"

Brian Petro
  • 1,577
  • 16
  • 32