Add debates translation interface

Also fix broken spec after removing translatable attributes from
strong_parameters definition. Now we need to send these attributes
as nested translations attributes.

Use activerecord.yml title attribute label so form helper could load it
from default location.
This commit is contained in:
Senén Rodero Rodríguez
2018-12-23 18:31:36 +01:00
committed by voodoorai2000
parent f77e7df33e
commit 51cda51155
6 changed files with 43 additions and 21 deletions

View File

@@ -2,6 +2,7 @@ class DebatesController < ApplicationController
include FeatureFlags include FeatureFlags
include CommentableActions include CommentableActions
include FlagActions include FlagActions
include Translatable
before_action :parse_tag_filter, only: :index before_action :parse_tag_filter, only: :index
before_action :authenticate_user!, except: [:index, :show, :map] before_action :authenticate_user!, except: [:index, :show, :map]
@@ -55,7 +56,8 @@ class DebatesController < ApplicationController
private private
def debate_params def debate_params
params.require(:debate).permit(:title, :description, :tag_list, :terms_of_service) attributes = [:tag_list, :terms_of_service]
params.require(:debate).permit(attributes, translation_params(Debate))
end end
def resource_model def resource_model

View File

@@ -1,17 +1,29 @@
<%= form_for(@debate) do |f| %> <%= render "admin/shared/globalize_locales", resource: @debate %>
<%= translatable_form_for(@debate) do |f| %>
<%= render "shared/errors", resource: @debate %> <%= render "shared/errors", resource: @debate %>
<div class="row"> <div class="row">
<div class="small-12 column">
<%= f.label :title, t("debates.form.debate_title") %> <%= f.translatable_fields do |translations_form| %>
<%= f.text_field :title, maxlength: Debate.title_max_length, placeholder: t("debates.form.debate_title"), label: false, data: {js_suggest_result: "js_suggest_result", js_suggest: "#js-suggest", js_url: suggest_debates_path}%> <div class="small-12 column">
</div> <%= translations_form.text_field :title,
<div id="js-suggest"></div> maxlength: Debate.title_max_length,
<div class="ckeditor small-12 column"> placeholder: t("debates.form.debate_title"),
<%= f.label :description, t("debates.form.debate_text") %> data: { js_suggest_result: "js_suggest_result",
<%= f.cktext_area :description, maxlength: Debate.description_max_length, ckeditor: { language: I18n.locale }, label: false %> js_suggest: "#js-suggest",
</div> js_url: suggest_debates_path } %>
</div>
<div id="js-suggest"></div>
<div class="ckeditor small-12 column">
<%= translations_form.cktext_area :description,
maxlength: Debate.description_max_length,
ckeditor: { language: I18n.locale },
label: t("debates.form.debate_text") %>
</div>
<% end %>
<%= f.invisible_captcha :subtitle %> <%= f.invisible_captcha :subtitle %>

View File

@@ -181,7 +181,7 @@ en:
author: "Author" author: "Author"
description: "Opinion" description: "Opinion"
terms_of_service: "Terms of service" terms_of_service: "Terms of service"
title: "Title" title: "Debate title"
proposal: proposal:
author: "Author" author: "Author"
title: "Title" title: "Title"

View File

@@ -183,7 +183,7 @@ es:
author: "Autor" author: "Autor"
description: "Opinión" description: "Opinión"
terms_of_service: "Términos de servicio" terms_of_service: "Términos de servicio"
title: "Título" title: "Título del debate"
proposal: proposal:
author: "Autor" author: "Autor"
title: "Título" title: "Título"

View File

@@ -12,16 +12,19 @@ describe DebatesController do
end end
it "creates an ahoy event" do it "creates an ahoy event" do
debate_attributes = {
terms_of_service: "1",
translations_attributes: {
"0" => {
title: "A sample debate",
description: "this is a sample debate",
locale: "en"
}
}
}
sign_in create(:user) sign_in create(:user)
post :create, params: { post :create, debate: debate_attributes
debate: {
title: "A sample debate",
description: "this is a sample debate",
terms_of_service: 1
}
}
expect(Ahoy::Event.where(name: :debate_created).count).to eq 1 expect(Ahoy::Event.where(name: :debate_created).count).to eq 1
expect(Ahoy::Event.last.properties["debate_id"]).to eq Debate.last.id expect(Ahoy::Event.last.properties["debate_id"]).to eq Debate.last.id
end end

View File

@@ -11,6 +11,11 @@ describe "Debates" do
context "Concerns" do context "Concerns" do
it_behaves_like "notifiable in-app", Debate it_behaves_like "notifiable in-app", Debate
it_behaves_like "relationable", Debate it_behaves_like "relationable", Debate
it_behaves_like "translatable",
"debate",
"edit_debate_path",
%w[title],
{ "description" => :ckeditor }
end end
scenario "Index" do scenario "Index" do