Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Whenever a site is stored, a document is created in the "sites" collection in MongoDB containing the time zone.
- Loading branch information
Showing
8 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
class Site < ActiveRecord::Base | ||
|
||
validates_presence_of :name | ||
validates_presence_of :name, :time_zone | ||
|
||
before_create :create_mongo_site | ||
|
||
def time_zone_id | ||
ActiveSupport::TimeZone::MAPPING[time_zone] | ||
end | ||
|
||
private | ||
|
||
def create_mongo_site | ||
self.token = Mongo.db["sites"].insert({ :tz => time_zone_id }).to_s | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
= simple_form_for @site do |f| | ||
= f.input :name, :label => "Site name" | ||
= f.input :time_zone | ||
= f.button :submit, "Save" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class AddTokenToSites < ActiveRecord::Migration | ||
def self.up | ||
add_column :sites, :token, :string | ||
end | ||
|
||
def self.down | ||
remove_column :sites, :token | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class AddTimeZoneToSites < ActiveRecord::Migration | ||
def self.up | ||
add_column :sites, :time_zone, :string | ||
end | ||
|
||
def self.down | ||
remove_column :sites, :time_zone | ||
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
factory :site do | ||
name "Snowfinch" | ||
time_zone "Helsinki" | ||
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