Browse Source

work in detected timezone

pull/1/head
Claudius Nicolae 12 years ago
parent
commit
0e70a0dcf8
  1. 10
      Gemfile
  2. 37
      Gemfile.lock
  3. 3
      app/assets/javascripts/application.js.coffee
  4. 4
      app/assets/javascripts/components/config.js.coffee.erb
  5. 13
      app/controllers/application_controller.rb

10
Gemfile

@ -34,7 +34,7 @@ gem 'seedbank', '~> 0.1.3'
gem 'rails_admin', '~> 0.4.5'
gem 'rails-settings-cached', '~> 0.2.2'
gem 'unicorn', '~> 4.5.0'
gem "audited-activerecord", '~> 3.0'
gem 'audited-activerecord', '~> 3.0'
# Gems used only for assets and not required
# in production environments by default.
@ -44,8 +44,13 @@ group :assets do
gem 'bootstrap-sass', '~> 2.2.0'
gem 'font-awesome-sass-rails', '~> 3.0.0'
gem 'webshims-rails', '~> 0.4.7'
gem 'detect_timezone_rails', '~> 0.0.3'
gem 'jquery-cookie-rails', '~> 1.2.0',
git: 'git://github.com/RyanScottLewis/jquery-cookie-rails.git'
gem 'coffee-rails', "~> 3.2.1"
gem 'uglifier', '>= 1.0.3'
gem 'oily_png', '1.0.2'
gem 'turbo-sprockets-rails3', '0.3.6'
gem 'therubyracer'
end
@ -62,6 +67,9 @@ group :development do
gem 'capistrano-ext', '~> 1.2.1'
gem 'mongrel', '>= 1.2.0.pre2'
gem 'quiet_assets', '~> 1.0.1'
gem 'meta_request', '0.2.1'
gem 'parallel_tests', '0.10.0'
gem 'progress_bar', require: false
end
group :test, :development do

37
Gemfile.lock

@ -1,3 +1,12 @@
GIT
remote: git://github.com/RyanScottLewis/jquery-cookie-rails.git
revision: f35da80d8ff720f7164924cc40abd2688f834ca6
specs:
jquery-cookie-rails (1.2.0)
jquery-rails (~> 2.0)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
GIT
remote: https://github.com/KimNorgaard/validates_hostname.git
revision: 6421e9bd8261a2fe010c627191a0dbe30352469f
@ -101,6 +110,8 @@ GEM
daemons (1.0.10)
dalli (2.6.2)
database_cleaner (0.7.2)
detect_timezone_rails (0.0.3)
railties (~> 3.1)
devise (2.1.3)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
@ -118,6 +129,7 @@ GEM
railties (>= 3.0.0)
faker (1.0.1)
i18n (~> 0.4)
fattr (2.2.1)
ffi (1.0.11)
file-tail (1.0.12)
tins (~> 0.5)
@ -164,6 +176,9 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mail_form (1.3.0)
meta_request (0.2.1)
rack-contrib
rails
method_source (0.8.1)
mime-types (1.21)
mongrel (1.2.0.pre2)
@ -183,10 +198,20 @@ GEM
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
nokogiri (1.5.6)
oily_png (1.0.2)
chunky_png (~> 1.2.1)
options (2.3.0)
fattr
orm_adapter (0.4.0)
parallel (0.6.2)
parallel_tests (0.10.0)
parallel
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.3)
progress_bar (0.4.0)
highline (~> 1.6.1)
options (~> 2.3.0)
pry (0.9.12)
coderay (~> 1.0.5)
method_source (~> 0.8)
@ -196,6 +221,8 @@ GEM
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
rack-contrib (1.1.0)
rack (>= 0.9.1)
rack-pjax (0.7.0)
nokogiri (~> 1.5)
rack (~> 1.3)
@ -317,6 +344,9 @@ GEM
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
turbo-sprockets-rails3 (0.3.6)
railties (> 3.2.8, < 4.0.0)
sprockets (>= 2.0.0)
turbolinks (1.0.0)
coffee-rails
tzinfo (0.3.36)
@ -353,19 +383,25 @@ DEPENDENCIES
concerned_with (~> 0.1.0)
dalli (~> 2.6.2)
database_cleaner (~> 0.7.1)
detect_timezone_rails (~> 0.0.3)
devise (~> 2.1.0)
factory_girl_rails (~> 1.6.0)
faker (~> 1.0.1)
font-awesome-sass-rails (~> 3.0.0)
guard-rspec (~> 0.6.0)
guard-spork (~> 0.5.1)
jquery-cookie-rails (~> 1.2.0)!
jquery-rails (~> 2.1.3)
libnotify (~> 0.7.2)
mail_form (~> 1.3.0)
meta_request (= 0.2.1)
mongrel (>= 1.2.0.pre2)
mysql2
navigasmic (~> 0.5.6)!
nilify_blanks (~> 1.0.0)
oily_png (= 1.0.2)
parallel_tests (= 0.10.0)
progress_bar
quiet_assets (~> 1.0.1)
rails (= 3.2.12)
rails-backbone (~> 0.7.0)
@ -384,6 +420,7 @@ DEPENDENCIES
squeel (~> 1.0.0)
switch_user (~> 0.6.0)
therubyracer
turbo-sprockets-rails3 (= 0.3.6)
turbolinks (~> 1.0.0)
uglifier (>= 1.0.3)
unicorn (~> 4.5.0)

3
app/assets/javascripts/application.js.coffee

@ -11,5 +11,8 @@
#= require slides
#= require bootstrap
#= require active_scaffold
#= require jquery.cookie
#= require detect_timezone
#= require jquery.detect_timezone
#= require_tree ./components
#= require_self

4
app/assets/javascripts/components/config.js.coffee.erb

@ -0,0 +1,4 @@
$.cookie('time_zone',
$.fn.get_timezone('default': '<%= Rails.configuration.time_zone %>'),
{ path: '/' }
)

13
app/controllers/application_controller.rb

@ -1,6 +1,7 @@
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :check_honeypot
around_filter :set_timezone
helper_method :client_remote_ip
layout :scoped_layout
@ -11,6 +12,18 @@ class ApplicationController < ActionController::Base
protected
def set_timezone
old_time_zone = Time.zone
if user_signed_in? && current_user.timezone.present?
Time.zone = current_user.timezone
elsif cookies[:time_zone].present?
Time.zone = cookies[:time_zone]
end
yield
ensure
Time.zone = old_time_zone
end
def scoped_layout
return false if request.xhr?
return 'admin' if devise_controller? && resource_name == :admin

Loading…
Cancel
Save