In rails controllers, how to prevent double submit (when user double-clic submit button or hit enter twice)?

后端 未结 8 2293
天命终不由人
天命终不由人 2021-02-19 09:50

Well, everything\'s in the title but I\'ll explain a little more :-)

My rails app contain many forms (Ajaxified or not).

To prevent users to submit twice or more

8条回答
  •  一向
    一向 (楼主)
    2021-02-19 10:03

    Try using Redis locking and surround your block with something like

    Redis.current.lock("#{current_user.id}.action_name") do
       # Some code
    end
    

    This is the gem I'm using https://github.com/mlanett/redis-lock

提交回复
热议问题