Giter Club home page Giter Club logo

Comments (5)

fabn avatar fabn commented on July 20, 2024

Have you solved this? I was looking for the same thing. IMHO this (awesome) gem should not add empty translations

from activeadmin-globalize.

fabn avatar fabn commented on July 20, 2024

PS. I've taken your code and in my attempt the '_destroy' flag seems to work.

from activeadmin-globalize.

codingluke avatar codingluke commented on July 20, 2024

@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.

fabn avatar fabn commented on July 20, 2024

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.

sepastian avatar sepastian commented on July 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.