Class: CookieAlert::CookiesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CookieAlert::CookiesController
- Defined in:
- app/controllers/cookie_alert/cookies_controller.rb
Instance Method Summary collapse
-
#cookie_accepted ⇒ Object
Implement cookie acceptance when a visitor click the 'accept' button.
Instance Method Details
#cookie_accepted ⇒ Object
Implement cookie acceptance when a visitor click the 'accept' button
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/cookie_alert/cookies_controller.rb', line 7 def # Get the visitor's current page URL or, if nil?, default to the application root. Resue block needed for bots visitor_current_url = begin .signed[CookieAlert.config..to_sym].split(CookieAlert.config.)[1] rescue main_app.root_path end # Set the Cookie value to 'accepted' if CookieAlert.config. == 'permanent' # Set a permanent cookie .permanent.signed[CookieAlert.config..to_sym] = 'accepted' elsif CookieAlert.config. == 'fixed_duration' # Set a fixed duration cookie .permanent.signed[CookieAlert.config..to_sym] = { value: 'accepted', expires: CookieAlert.config..days.from_now } else # Set a session cookie .signed[CookieAlert.config..to_sym] = 'accepted' end # If the request is HTML then redirect the visitor back to their original page # If the request is javascript then render the javascript partial respond_to do |format| format.html { redirect_to(visitor_current_url) } format.js { render template: "cookie_alert/cookies/cookie_accepted" } end end |