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 CommentableActions
include FlagActions
include Translatable
before_action :parse_tag_filter, only: :index
before_action :authenticate_user!, except: [:index, :show, :map]
@@ -55,7 +56,8 @@ class DebatesController < ApplicationController
private
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
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 %>
<div class="row">
<%= f.translatable_fields do |translations_form| %>
<div class="small-12 column">
<%= f.label :title, t("debates.form.debate_title") %>
<%= 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}%>
<%= translations_form.text_field :title,
maxlength: Debate.title_max_length,
placeholder: t("debates.form.debate_title"),
data: { js_suggest_result: "js_suggest_result",
js_suggest: "#js-suggest",
js_url: suggest_debates_path } %>
</div>
<div id="js-suggest"></div>
<div class="ckeditor small-12 column">
<%= f.label :description, t("debates.form.debate_text") %>
<%= f.cktext_area :description, maxlength: Debate.description_max_length, ckeditor: { language: I18n.locale }, label: false %>
<%= 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 %>

View File

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

View File

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

View File

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

View File

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