Add :except and :only options to translatable_params method
Allow to choose among resource model translatable attributes.
This commit is contained in:
committed by
voodoorai2000
parent
8103a16031
commit
5dc0f7f054
@@ -3,10 +3,13 @@ module Translatable
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def translation_params(resource_model)
|
def translation_params(resource_model, options = {})
|
||||||
{
|
attributes = [:id, :locale, :_destroy]
|
||||||
translations_attributes: [:id, :_destroy, :locale] +
|
if options[:only]
|
||||||
resource_model.translated_attribute_names
|
attributes += [*options[:only]]
|
||||||
}
|
else
|
||||||
|
attributes += resource_model.translated_attribute_names
|
||||||
|
end
|
||||||
|
{ translations_attributes: attributes - [*options[:except]] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -104,12 +104,14 @@ class ProposalsController < ApplicationController
|
|||||||
documents_attributes: [:id, :title, :attachment, :cached_attachment,
|
documents_attributes: [:id, :title, :attachment, :cached_attachment,
|
||||||
:user_id, :_destroy],
|
:user_id, :_destroy],
|
||||||
map_location_attributes: [:latitude, :longitude, :zoom]]
|
map_location_attributes: [:latitude, :longitude, :zoom]]
|
||||||
params.require(:proposal).permit(attributes, translation_params(Proposal))
|
translations_attributes = translation_params(Proposal, except: :retired_explanation)
|
||||||
|
params.require(:proposal).permit(attributes, translations_attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
def retired_params
|
def retired_params
|
||||||
attributes = [:retired_reason]
|
attributes = [:retired_reason]
|
||||||
params.require(:proposal).permit(attributes, translation_params(Proposal))
|
translations_attributes = translation_params(Proposal, only: :retired_explanation)
|
||||||
|
params.require(:proposal).permit(attributes, translations_attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
def resource_model
|
def resource_model
|
||||||
|
|||||||
Reference in New Issue
Block a user