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:
committed by
voodoorai2000
parent
f77e7df33e
commit
51cda51155
@@ -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
|
||||||
|
|||||||
@@ -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">
|
||||||
|
|
||||||
|
<%= f.translatable_fields do |translations_form| %>
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<%= f.label :title, t("debates.form.debate_title") %>
|
<%= translations_form.text_field :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}%>
|
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>
|
||||||
<div id="js-suggest"></div>
|
<div id="js-suggest"></div>
|
||||||
|
|
||||||
<div class="ckeditor small-12 column">
|
<div class="ckeditor small-12 column">
|
||||||
<%= f.label :description, t("debates.form.debate_text") %>
|
<%= translations_form.cktext_area :description,
|
||||||
<%= f.cktext_area :description, maxlength: Debate.description_max_length, ckeditor: { language: I18n.locale }, label: false %>
|
maxlength: Debate.description_max_length,
|
||||||
|
ckeditor: { language: I18n.locale },
|
||||||
|
label: t("debates.form.debate_text") %>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<%= f.invisible_captcha :subtitle %>
|
<%= f.invisible_captcha :subtitle %>
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -12,16 +12,19 @@ describe DebatesController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "creates an ahoy event" do
|
it "creates an ahoy event" do
|
||||||
|
debate_attributes = {
|
||||||
sign_in create(:user)
|
terms_of_service: "1",
|
||||||
|
translations_attributes: {
|
||||||
post :create, params: {
|
"0" => {
|
||||||
debate: {
|
|
||||||
title: "A sample debate",
|
title: "A sample debate",
|
||||||
description: "this is 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.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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user