Skip to content

gem upgrade 2016 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Jstz::Rails

This is [jstz.js aka jsTimezoneDetect](https://bitbucket.org/pellepim/jstimezonedetect/) GEMified for the Rails >= 3.1 asset pipeline through the following:
This is [jstz.js aka jsTimezoneDetect](https://bitbucket.org/pellepim/jstimezonedetect/) GEMified for the Rails >= 4.1 asset pipeline through the following:

bundle gem jstz-rails
cd jstz-rails
Expand Down Expand Up @@ -57,20 +57,31 @@ Or install it yourself as:

Add to **application.js**

//= require jstz.js
//= require jstz

Add to **your.js** to write browser detected timezone to a cookie

document.cookie = 'time_zone='+jstz.determine().timezone.name()+';';

var timeZone = jstz.determine();
document.cookie = 'time_zone='+timeZone.name()+';';

Add to **application_controller.rb** to set application's timezone from cookie

before_filter :set_timezone
private
def set_timezone
Time.zone = cookies["time_zone"]
Time.zone = cookies[:time_zone]
end

Another example of cookie usage in **application_controller.rb**

around_action :set_timezone
private
def set_timezone
Time.use_zone(cookies[:time_zone]) do
yield
end
end

Or add to view to set default from cookie (e.g. simple_form)

<%= f.input :time_zone, priority: /US/, :default => ActiveSupport::TimeZone.all.reject {|zone| zone.tzinfo != TZInfo::Timezone.get(cookies["time_zone"])}.first.name %>
Expand Down
2 changes: 1 addition & 1 deletion jstz-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
gem.homepage = "http://rubygems.org/gems/jstz-rails"

gem.files = Dir["{lib,vendor}/**/*"] + ["LICENSE", "README.md"]
gem.add_dependency "railties", ">= 3.1"
gem.add_dependency "railties", ">= 4.1"
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.name = "jstz-rails"
Expand Down
2 changes: 1 addition & 1 deletion lib/jstz-rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Jstz
module Rails
VERSION = "1.0.4.1"
VERSION = "1.0.6"
end
end
Loading