Update polls translatable fields

The `:name` attribute is still allowed in the controller because some
forks use it when creating a poll from a budget.
This commit is contained in:
Javi Martín
2018-10-10 14:37:43 +02:00
committed by decabeza
parent 601fe666d9
commit 6478bb70c2
5 changed files with 29 additions and 17 deletions

View File

@@ -61,10 +61,10 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
def poll_params
image_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :summary, :description,
:results_enabled, :stats_enabled, geozone_ids: [],
attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :results_enabled,
:stats_enabled, geozone_ids: [],
image_attributes: image_attributes]
params.require(:poll).permit(*attributes, *translation_params(Poll))
params.require(:poll).permit(*attributes, translation_params(Poll))
end
def search_params

View File

@@ -8,6 +8,7 @@ class Poll < ActiveRecord::Base
translates :summary, touch: true
translates :description, touch: true
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
RECOUNT_DURATION = 1.week
@@ -24,7 +25,9 @@ class Poll < ActiveRecord::Base
has_and_belongs_to_many :geozones
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
validates :name, presence: true
translation_class.instance_eval do
validates :name, presence: true
end
validate :date_range

View File

@@ -1,9 +1,7 @@
<%= render "admin/shared/globalize_locales", resource: @poll %>
<%= translatable_form_for [:admin, @poll] do |f| %>
<div class="small-12 medium-6 column">
<%= f.translatable_text_field :name %>
</div>
<%= render "shared/errors", resource: @poll %>
<div class="clear">
<div class="small-12 medium-6 column">
@@ -19,13 +17,20 @@
</div>
</div>
<div class="small-12 column">
<%=f.translatable_text_area :summary, rows: 4%>
</div>
<div class="small-12 column">
<%=f.translatable_text_area :description, rows: 8%>
</div>
<%= f.translatable_fields do |translations_form| %>
<div class="small-12 medium-6 column">
<%= translations_form.text_field :name %>
</div>
<div class="small-12 column">
<%= translations_form.text_area :summary, rows: 4 %>
</div>
<div class="small-12 column">
<%= translations_form.text_area :description, rows: 8 %>
</div>
<% end %>
<div class="small-12 column">
<%= render 'images/admin_image', imageable: @poll, f: f %>

View File

@@ -185,6 +185,10 @@ en:
geozone_restricted: "Restricted by geozone"
summary: "Summary"
description: "Description"
poll/translation:
name: "Name"
summary: "Summary"
description: "Description"
poll/question:
title: "Question"
summary: "Summary"

View File

@@ -60,11 +60,11 @@ feature 'Admin polls' do
start_date = 1.week.from_now
end_date = 2.weeks.from_now
fill_in "poll_name_en", with: "Upcoming poll"
fill_in "Name", with: "Upcoming poll"
fill_in 'poll_starts_at', with: start_date.strftime("%d/%m/%Y")
fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y")
fill_in 'poll_summary_en', with: "Upcoming poll's summary. This poll..."
fill_in 'poll_description_en', with: "Upcomming poll's description. This poll..."
fill_in 'Summary', with: "Upcoming poll's summary. This poll..."
fill_in 'Description', with: "Upcomming poll's description. This poll..."
expect(page).not_to have_css("#poll_results_enabled")
expect(page).not_to have_css("#poll_stats_enabled")
@@ -88,7 +88,7 @@ feature 'Admin polls' do
expect(page).to have_css("img[alt='#{poll.image.title}']")
fill_in "poll_name_en", with: "Next Poll"
fill_in "Name", with: "Next Poll"
fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y")
click_button "Update poll"