Skip to content

Instantly share code, notes, and snippets.

@maier-stefan
Created January 23, 2015 15:36
Show Gist options
  • Save maier-stefan/c517783313590927b678 to your computer and use it in GitHub Desktop.
Save maier-stefan/c517783313590927b678 to your computer and use it in GitHub Desktop.
communication with rails and coffeescript
The page at localhost:3000 says:
first_time=true; profile=afidwogiowjero;
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
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