Comments (5)
Have you solved this? I was looking for the same thing. IMHO this (awesome) gem should not add empty translations
from activeadmin-globalize.
PS. I've taken your code and in my attempt the '_destroy'
flag seems to work.
from activeadmin-globalize.
@fabn really it works for you? thats great news! So I have to go through my depended code. Maybe I will crate a playground app to test it without dependencies. It would be also great do have a generic solution :)
At the moment I make a pretty ugly workaround. I set the title to "delete_me_after_save" and delete the marked translation with e "after_save" hook.
from activeadmin-globalize.
Yes, it does. I've used your code in my application controller to make it generic in this way when I use it on my resources I only need to put the before_filter line in my resources. Keep in mind that this is just a proof of concept, I haven't used this code in production (yet).
private
def remove_or_mark_empty_translations
# Retrieve used model name
model = controller_name.singularize.to_sym
# walk the submitted attributes
params[model][:translations_attributes].each do |t|
# iterates through the fields and checks if they are empty
# the first two entries (id and locale) are ignored
if !(t.last.map { |_, v| v.empty? ? true : false }[2..-1]).include?(false)
if t.last[:id].empty?
# If id is also empty, remove from params
params[model][:translations_attributes].delete(t.first)
else
# otherwise mark to destroy
params[model][:translations_attributes][t.first]['_destroy'] = '1'
end
end
end
end
from activeadmin-globalize.
Hi!
I agree, activeadmin-globalize3 should definitely not create empty translations.
I took your filter and registered it in ActionController::Base
during initialization of the Engine
- meaning that it will always get triggered on :create
and :update
, for all models, without manually registering any filters.
Maybe it would also be good to make this an optional feature, i.e. provide config[:delete_existing_empty_translations]
and config[:delete_new_empty_translations]
. But both should be on by default, I would say not creating any empty translations is what a user would expect. (Will look into creating options when I find the time.)
Could you try this out? Does it work for you? What do you think?
from activeadmin-globalize.
Related Issues (19)
- Validation errors are not shown HOT 1
- duplicate inputs when used inside form HOT 11
- css not precompiled on heroku HOT 1
- Unable to use translated_inputs with form partial HOT 2
- Save empty translations HOT 1
- Internationalization for translated fields doesn't work HOT 12
- Set default open tab
- Asset Pipeline ... HOT 4
- Problem with validations declared in active_admin_translates HOT 2
- Version for Rails 3 HOT 2
- Validation: at least a language
- Updating record creates new translation records instead of updating them HOT 3
- After upgraded to AA 1.0.0.pre notebook tabs urls are broken HOT 1
- f.translated_inputs can't be split up across input-groups HOT 1
- Sorting of translated column leads to an exception HOT 1
- activeadmin 9132da6 form_buffer removed HOT 7
- I can't use "translated_inputs" inside "has_many" HOT 3
- Save slug for all availabe locales HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from activeadmin-globalize.