Update poll questions translatable fields
We need to replace ".title=" by ".title_#{locale}=" in one place because
for some reason globalize builds a new translation record when using the
latter but it doesn't build one when using the former.
This commit is contained in:
@@ -56,8 +56,8 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController
|
||||
private
|
||||
|
||||
def question_params
|
||||
attributes = [:poll_id, :title, :question, :proposal_id]
|
||||
params.require(:poll_question).permit(*attributes, *translation_params(Poll::Question))
|
||||
attributes = [:poll_id, :question, :proposal_id]
|
||||
params.require(:poll_question).permit(*attributes, translation_params(Poll::Question))
|
||||
end
|
||||
|
||||
def search_params
|
||||
|
||||
@@ -7,6 +7,7 @@ class Poll::Question < ActiveRecord::Base
|
||||
|
||||
translates :title, touch: true
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
|
||||
belongs_to :poll
|
||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||
@@ -17,12 +18,13 @@ class Poll::Question < ActiveRecord::Base
|
||||
has_many :partial_results
|
||||
belongs_to :proposal
|
||||
|
||||
validates :title, presence: true
|
||||
translation_class.instance_eval do
|
||||
validates :title, presence: true, length: { minimum: 4 }
|
||||
end
|
||||
|
||||
validates :author, presence: true
|
||||
validates :poll_id, presence: true
|
||||
|
||||
validates :title, length: { minimum: 4 }
|
||||
|
||||
scope :by_poll_id, ->(poll_id) { where(poll_id: poll_id) }
|
||||
|
||||
scope :sort_for_list, -> { order('poll_questions.proposal_id IS NULL', :created_at)}
|
||||
@@ -47,7 +49,7 @@ class Poll::Question < ActiveRecord::Base
|
||||
self.author = proposal.author
|
||||
self.author_visible_name = proposal.author.name
|
||||
self.proposal_id = proposal.id
|
||||
self.title = proposal.title
|
||||
send(:"title_#{Globalize.locale}=", proposal.title)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
label: t("admin.questions.new.poll_label") %>
|
||||
</div>
|
||||
|
||||
<%= f.translatable_text_field :title %>
|
||||
<%= f.translatable_fields do |translations_form| %>
|
||||
<%= translations_form.text_field :title %>
|
||||
<% end %>
|
||||
|
||||
<div class="small-12 medium-4 large-2 margin-top">
|
||||
<%= f.submit(class: "button success expanded", value: t("shared.save")) %>
|
||||
|
||||
@@ -194,6 +194,8 @@ en:
|
||||
summary: "Summary"
|
||||
description: "Description"
|
||||
external_url: "Link to additional documentation"
|
||||
poll/question/translation:
|
||||
title: "Question"
|
||||
signature_sheet:
|
||||
signable_type: "Signable type"
|
||||
signable_id: "Signable ID"
|
||||
|
||||
@@ -194,6 +194,8 @@ es:
|
||||
summary: "Resumen"
|
||||
description: "Descripción"
|
||||
external_url: "Enlace a documentación adicional"
|
||||
poll/question/translation:
|
||||
title: "Pregunta"
|
||||
signature_sheet:
|
||||
signable_type: "Tipo de hoja de firmas"
|
||||
signable_id: "ID Propuesta ciudadana/Propuesta inversión"
|
||||
|
||||
@@ -46,7 +46,7 @@ feature 'Admin poll questions' do
|
||||
click_link "Create question"
|
||||
|
||||
select 'Movies', from: 'poll_question_poll_id'
|
||||
fill_in 'poll_question_title_en', with: title
|
||||
fill_in 'Question', with: title
|
||||
|
||||
click_button 'Save'
|
||||
|
||||
@@ -61,7 +61,7 @@ feature 'Admin poll questions' do
|
||||
click_link "Create question"
|
||||
|
||||
expect(page).to have_current_path(new_admin_question_path, ignore_query: true)
|
||||
expect(page).to have_field('poll_question_title_en', with: proposal.title)
|
||||
expect(page).to have_field('Question', with: proposal.title)
|
||||
|
||||
select 'Proposals', from: 'poll_question_poll_id'
|
||||
|
||||
@@ -84,7 +84,7 @@ feature 'Admin poll questions' do
|
||||
|
||||
old_title = question1.title
|
||||
new_title = "Potatoes are great and everyone should have one"
|
||||
fill_in 'poll_question_title_en', with: new_title
|
||||
fill_in 'Question', with: new_title
|
||||
|
||||
click_button 'Save'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user