Make polls translatable
This commit is contained in:
@@ -28,6 +28,20 @@ section "Creating polls" do
|
||||
ends_at: 1.month.ago,
|
||||
results_enabled: true,
|
||||
stats_enabled: true)
|
||||
|
||||
Poll.find_each do |poll|
|
||||
name = poll.name
|
||||
I18n.available_locales.map do |locale|
|
||||
neutral_locale = locale.to_s.downcase.underscore.to_sym
|
||||
Globalize.with_locale(neutral_locale) do
|
||||
poll.name = "#{name} (#{locale})"
|
||||
poll.summary = "Summary for locale #{locale}"
|
||||
poll.description = "Description for locale #{locale}"
|
||||
end
|
||||
end
|
||||
poll.save!
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
section "Creating Poll Questions & Answers" do
|
||||
|
||||
15
db/migrate/20180730213824_add_poll_translations.rb
Normal file
15
db/migrate/20180730213824_add_poll_translations.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class AddPollTranslations < ActiveRecord::Migration
|
||||
|
||||
def self.up
|
||||
Poll.create_translation_table!(
|
||||
name: :string,
|
||||
summary: :text,
|
||||
description: :text
|
||||
)
|
||||
end
|
||||
|
||||
def self.down
|
||||
Poll.drop_translation_table!
|
||||
end
|
||||
|
||||
end
|
||||
13
db/schema.rb
13
db/schema.rb
@@ -900,6 +900,19 @@ ActiveRecord::Schema.define(version: 20180813141443) do
|
||||
add_index "poll_shifts", ["booth_id"], name: "index_poll_shifts_on_booth_id", using: :btree
|
||||
add_index "poll_shifts", ["officer_id"], name: "index_poll_shifts_on_officer_id", using: :btree
|
||||
|
||||
create_table "poll_translations", force: :cascade do |t|
|
||||
t.integer "poll_id", null: false
|
||||
t.string "locale", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "name"
|
||||
t.text "summary"
|
||||
t.text "description"
|
||||
end
|
||||
|
||||
add_index "poll_translations", ["locale"], name: "index_poll_translations_on_locale", using: :btree
|
||||
add_index "poll_translations", ["poll_id"], name: "index_poll_translations_on_poll_id", using: :btree
|
||||
|
||||
create_table "poll_voters", force: :cascade do |t|
|
||||
t.string "document_number"
|
||||
t.string "document_type"
|
||||
|
||||
Reference in New Issue
Block a user