Created
January 23, 2015 15:36
-
-
Save maier-stefan/c517783313590927b678 to your computer and use it in GitHub Desktop.
communication with rails and coffeescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The page at localhost:3000 says: | |
first_time=true; profile=afidwogiowjero; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
# Prevent CSRF attacks by raising an exception. | |
# For APIs, you may want to use :null_session instead. | |
protect_from_forgery with: :exception | |
before_action :first_time_cookie_to_js, :set_hash | |
after_filter :set_first_time_cookie | |
private | |
def is_active controller | |
'active' if params[:controller] == controller | |
end | |
def set_first_time_cookie | |
## trigger jquery model popup | |
cookies.permanent[:first_time] ||= true | |
end | |
def first_time_cookie_to_js | |
### cookie to var and to js available.output in js is "first_time=true" if it is set | |
@cookie = cookies[:first_time] | |
end | |
def set_hash | |
@hashids = Hashids.new(("blah blah blah", 8) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ready = -> | |
alert(@cookie) | |
unless @cookie == "true" | |
$('#myModal').modal() | |
$(document).on('page:change', ready) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment