Make questions translatable
This commit is contained in:
@@ -47,10 +47,18 @@ end
|
||||
section "Creating Poll Questions & Answers" do
|
||||
Poll.find_each do |poll|
|
||||
(1..4).to_a.sample.times do
|
||||
question = Poll::Question.create!(author: User.all.sample,
|
||||
title: Faker::Lorem.sentence(3).truncate(60) + '?',
|
||||
poll: poll)
|
||||
Faker::Lorem.words((2..4).to_a.sample).each do |answer|
|
||||
title = Faker::Lorem.sentence(3).truncate(60) + '?'
|
||||
question = Poll::Question.new(author: User.all.sample,
|
||||
title: title,
|
||||
poll: poll)
|
||||
I18n.available_locales.map do |locale|
|
||||
neutral_locale = locale.to_s.downcase.underscore.to_sym
|
||||
Globalize.with_locale(neutral_locale) do
|
||||
question.title = "#{title} (#{locale})"
|
||||
end
|
||||
end
|
||||
question.save!
|
||||
Faker::Lorem.words((2..4).to_a.sample).each do |title|
|
||||
description = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
|
||||
Poll::Question::Answer.create!(question: question,
|
||||
title: answer.capitalize,
|
||||
@@ -194,6 +202,13 @@ section "Creating Poll Questions from Proposals" do
|
||||
description: Faker::ChuckNorris.fact)
|
||||
end
|
||||
question.copy_attributes_from_proposal(proposal)
|
||||
title = question.title
|
||||
I18n.available_locales.map do |locale|
|
||||
neutral_locale = locale.to_s.downcase.underscore.to_sym
|
||||
Globalize.with_locale(neutral_locale) do
|
||||
question.title = "#{title} (#{locale})"
|
||||
end
|
||||
end
|
||||
question.save!
|
||||
end
|
||||
end
|
||||
@@ -209,6 +224,13 @@ section "Creating Successful Proposals" do
|
||||
description: Faker::ChuckNorris.fact)
|
||||
end
|
||||
question.copy_attributes_from_proposal(proposal)
|
||||
title = question.title
|
||||
I18n.available_locales.map do |locale|
|
||||
neutral_locale = locale.to_s.downcase.underscore.to_sym
|
||||
Globalize.with_locale(neutral_locale) do
|
||||
question.title = "#{title} (#{locale})"
|
||||
end
|
||||
end
|
||||
question.save!
|
||||
end
|
||||
end
|
||||
|
||||
13
db/migrate/20180731173147_add_poll_question_translations.rb
Normal file
13
db/migrate/20180731173147_add_poll_question_translations.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class AddPollQuestionTranslations < ActiveRecord::Migration
|
||||
|
||||
def self.up
|
||||
Poll::Question.create_translation_table!(
|
||||
title: :string
|
||||
)
|
||||
end
|
||||
|
||||
def self.down
|
||||
Poll::Question.drop_translation_table!
|
||||
end
|
||||
|
||||
end
|
||||
11
db/schema.rb
11
db/schema.rb
@@ -847,6 +847,17 @@ ActiveRecord::Schema.define(version: 20180813141443) do
|
||||
|
||||
add_index "poll_question_answers", ["question_id"], name: "index_poll_question_answers_on_question_id", using: :btree
|
||||
|
||||
create_table "poll_question_translations", force: :cascade do |t|
|
||||
t.integer "poll_question_id", null: false
|
||||
t.string "locale", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "title"
|
||||
end
|
||||
|
||||
add_index "poll_question_translations", ["locale"], name: "index_poll_question_translations_on_locale", using: :btree
|
||||
add_index "poll_question_translations", ["poll_question_id"], name: "index_poll_question_translations_on_poll_question_id", using: :btree
|
||||
|
||||
create_table "poll_questions", force: :cascade do |t|
|
||||
t.integer "proposal_id"
|
||||
t.integer "poll_id"
|
||||
|
||||
Reference in New Issue
Block a user