From 465418cf1dd44a3a4500e56453d708318a59eb32 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sat, 6 Sep 2014 18:18:08 +0300 Subject: [PATCH] Add a localised description to the tracks --- app/models/track.rb | 2 ++ app/views/home/_track.html.slim | 7 ++++++- ...103859_add_translation_tables_to_conferences.rb | 2 +- .../20140906151300_add_description_to_tracks.rb | 5 +++++ ...40906151433_add_translation_tables_to_tracks.rb | 14 ++++++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20140906151300_add_description_to_tracks.rb create mode 100644 db/migrate/20140906151433_add_translation_tables_to_tracks.rb diff --git a/app/models/track.rb b/app/models/track.rb index 6335631..80b8be3 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -5,6 +5,8 @@ class Track < ActiveRecord::Base validates :name, presence: true validates :color, presence: true, format: {with: /\A[a-f0-9]{6}\z/i} + translates :name, :description + def color=(hex_triplet) write_attribute :color, hex_triplet.gsub(/\A#/,'') if hex_triplet end diff --git a/app/views/home/_track.html.slim b/app/views/home/_track.html.slim index 2283ac2..c76c2fa 100644 --- a/app/views/home/_track.html.slim +++ b/app/views/home/_track.html.slim @@ -1 +1,6 @@ -li = track.name +li + strong + = track.name + \- + span + = track.description diff --git a/db/migrate/20140901103859_add_translation_tables_to_conferences.rb b/db/migrate/20140901103859_add_translation_tables_to_conferences.rb index ba159a8..4848e4b 100644 --- a/db/migrate/20140901103859_add_translation_tables_to_conferences.rb +++ b/db/migrate/20140901103859_add_translation_tables_to_conferences.rb @@ -9,6 +9,6 @@ class AddTranslationTablesToConferences < ActiveRecord::Migration end def down - Post.drop_translation_table! :migrate_data => true + Conference.drop_translation_table! :migrate_data => true end end diff --git a/db/migrate/20140906151300_add_description_to_tracks.rb b/db/migrate/20140906151300_add_description_to_tracks.rb new file mode 100644 index 0000000..e27dc9f --- /dev/null +++ b/db/migrate/20140906151300_add_description_to_tracks.rb @@ -0,0 +1,5 @@ +class AddDescriptionToTracks < ActiveRecord::Migration + def change + add_column :tracks, :description, :text + end +end diff --git a/db/migrate/20140906151433_add_translation_tables_to_tracks.rb b/db/migrate/20140906151433_add_translation_tables_to_tracks.rb new file mode 100644 index 0000000..28e3d8b --- /dev/null +++ b/db/migrate/20140906151433_add_translation_tables_to_tracks.rb @@ -0,0 +1,14 @@ +class AddTranslationTablesToTracks < ActiveRecord::Migration + def up + Track.create_translation_table!({ + name: :string, + description: :text + }, { + migrate_data: true + }) + end + + def down + Track.drop_translation_table! migrate_data: true + end +end