Module: SubmitOnce::ControllerHelper
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/submit_once/controller_helper.rb
Instance Method Summary collapse
-
#check_form_token ⇒ Object
TODO: force or no.
- #check_form_token! ⇒ Object
- #gen_form_token ⇒ Object
Instance Method Details
#check_form_token ⇒ Object
TODO: force or no
14 15 16 17 18 19 20 21 |
# File 'lib/submit_once/controller_helper.rb', line 14 def check_form_token if session[TOKEN_KEY] == params[TOKEN_KEY] session[TOKEN_KEY] = nil true else false end end |
#check_form_token! ⇒ Object
23 24 25 26 27 28 |
# File 'lib/submit_once/controller_helper.rb', line 23 def check_form_token! unless check_form_token # TODO: path, and i18n redirect_to '/', notice: "Couldn't repeat submit form" end end |
#gen_form_token ⇒ Object
30 31 32 33 |
# File 'lib/submit_once/controller_helper.rb', line 30 def gen_form_token @__form_token ||= (session[TOKEN_KEY] = Digest::SHA1.hexdigest((Time.now.to_i + rand(0xffffff)).to_s)[0..39]) end |