GithubHelp home page GithubHelp logo

activeadmin-globalize's Introduction

ActiveAdmin::Globalize

Makes it easy to translate your resource fields.

⚠️ Unmaintained ⚠️

Sorry, but I no longer work on ActiveAdmin often enough to justify mantaining this gem. Take it as it is. If you are interested to update and maintain the gem, please let me know! ❤️

Installation

gem "activeadmin-globalize", github: 'stefanoverna/activeadmin-globalize',
branch: 'master'

We still need to use GitHub because ActiveAdmin is still in active development and there's no released gem compatible with Rails 4.

Your model

active_admin_translates :title, :description do
  validates_presence_of :title
end

Editor configuration

# if you are using Rails 4 or Strong Parameters:
permit_params translations_attributes: [:locale, :title, :content]


index do
  # ...
  translation_status
  # ...
  default_actions
end

form do |f|
  # ...
  f.translated_inputs "Translated fields", switch_locale: false do |t|
    t.input :title
    t.input :content
  end
  # ...
end

If switch_locale is set, each tab will be rendered switching locale.

Friendly ID

If you want to use Friendly ID together with Globalize, please take a look at the activeadmin-seo gem.

Hints

To use the dashed locale keys as 'pt-BR' or 'pt-PT' you need to convert a string to symbol (in application.rb)

config.i18n.available_locales = [:en, :it, :de, :es, :"pt-BR"]

activeadmin-globalize's People

Contributors

ahmadsherif avatar delphaber avatar javierdechile avatar jklimke avatar joanamartins avatar marcusg avatar mzampetti avatar nebirhos avatar spleenteo avatar stefanoverna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

activeadmin-globalize's Issues

Validation: at least a language

Hello, using:

active_admin_translates :title, :description do
  validates_presence_of :title
end

activeadmin validates presence of title in all languages, is there a way to pass validation if one language (at least) is filled?

Thank you.

duplicate inputs when used inside form

I have a custom form using the activeadmin-globalize3 translated_inputs method. Everything looks good except the duplicate field for title. Any idea why this is produced?

inputs

The admin register messages.rb

ActiveAdmin.register Message do
  form :partial => 'form'
end

The code in _form.html.haml

= semantic_form_for [:admin, @message], :builder => ActiveAdmin::FormBuilder do |f|
  - f.translated_inputs do |t|
    = t.input :title
    = t.input :content
  = f.actions do
    = f.action :submit
    %li.cancel
      = link_to I18n.t('active_admin.cancel'), {:action => "index"}

I also tried to use the original Formtastic formbuilder instead of ActiveAdmin::FormBuilder, but with that I had no access to the translated_inputs method. Any help much appreciated!

Problem with validations declared in active_admin_translates

Hello! I have the following model that currently is managed through active admin:

class Item < ActiveRecord::Base
  validates :title, presence: true
  validates :short_description, presence: true

  translates :title, :short_description, fallbacks_for_empty_translations: true

  active_admin_translates :title, :short_description do
    validates :title, presence: true
    validates :short_description, presence: true
end

Recently I had the need to create some items through the seed file and I had the following problem with validations inside declared active_admin_translates.

What I do:

  1. I instantiate a new Item object and I assign both title and short_description for the locales I want.
  2. I call valid? and it returns true. I can see both title and short_description for all my locales.
  3. I call save but fails because of the validations declared in the active_admin_translates block. As in step 2, if I call title and short_description for all my locales I see the values I assigned on step 1.

What's going on here? Am I doing something wrong? Also, do I need the 2 validations outside the active_admin_translates block?

I really appreciate any help you can provide.

Validation errors are not shown

Hi,

Found your gem through a Google search and have been playing with it, pretty smooth sailing so far. One thing I noticed was that if a translation has validators attached to it, and if validation fails, the form is not saved (create and update) and no validation errors are shown.

Very simple example:

class Page < ActiveRecord::Base
  # attr_accessible :title, :body
  # translates :title, :body

  active_admin_translates :title, :body do
    validates_presence_of :title, :body
  end
end

Leaving either title or body empty keeps the Model from being created / update, as intended, but no validation errors are shown. Also, values are not persisted (i.e. emptying title on an already created model and submitting will show a form with the old title value and no errors).

Regards,
Lorenz

Internationalization for translated fields doesn't work

# app/admin.project.rb
ActiveAdmin.register Project do
  form do |f|
      f.translated_inputs do |t|
         t.input :title
      end 
  end
end
# config/locales/ru.yml
ru:
  activerecord:
    attributes:
      project:
        title: Название

I'm expecting label on input field to be 'Title' for English tab and 'Название' for Russian tab. Currently it shows 'Title' for both tabs.
Could you help me to solve the problem?

Set default open tab

In admin panel I have default Deutsche translation. How I can set default open tab English for example?

f.translated_inputs can't be split up across input-groups

Assuming I have the following setup:

form do |f|
    f.inputs do
      f.translated_inputs do |t|
        t.input :title
      end   

      f.translated_inputs do |t|
        t.input :description
      end
      f.input :slug
    end

    f.actions
  end

Now when I create a new entry. All translated values from the second translated_inputs block will be discarded.

As soon as the record is saved once, it works. But not for the initial save.

I have to group all entries in one translated_inputs block like so:

form do |f|
  f.inputs do |x|
    f.translated_inputs do |t|
      t.input :title
      t.input :description
    end
    f.input :slug
  end

  f.actions
end

I have quite a big model and the different translated values are grouped semantically. Due to this behaviour I now have to add a group just for the translated values.

Save slug for all availabe locales

Hi guys, i'm developing a site with friendly_id, globalize3 and activeadmin-globalize3.

I have a field named :name and I need to generate a slug for him, but the slug is only generated for the current locale.

Is this the correct behaviour? Has some way to work around this and save the slug for all available locales?

Thanks

After upgraded to AA 1.0.0.pre notebook tabs urls are broken

When click on a language Tab a route error is displayed:

Started GET "/admin/people/asdfasdf-asdf/.locale-es" for 127.0.0.1 at 2014-06-26 17:36:13 -0300

ActionController::RoutingError (No route matches [GET] "/admin/people/asdfasdf-asdf/.locale-es"):

Version for Rails 3

Hi @stefanoverna
I use you gem for an app which works with Rails3. As ActiveAdmin is not jet really stable on rails 4 and also other gems we are useing, I dont want to upgrade to Rails4 jet.
Now the globalize gem changed the name and also you already updated it. That's good. The only problem now is, that you have as the dependency globalize version 4:

# activeadmin-globalize.gemspec
s.add_dependency "globalize", '~> 4.0.0'

using Rails 3 it is recommended to use globalize version 3.1.0

gem 'globalize', '~> 3.1.0'

It would be great, if you could tag a version which uses Version 3. The features should be the same (https://github.com/globalize/globalize#installation). Otherwise I have to fork the gem and change it manually.
THX!

Asset Pipeline ...

I'm running into an issue when I try to integrate with the asset pipeline. The CSS and JS files are still being referenced as:

  • /stylesheets/active_admin/active_admin_globalize.css
  • /javascripts/active_admin/active_admin_globalize.js

I tried adding the CSS and JS to my precompile list, but this didn't make a difference.

Sorting of translated column leads to an exception

I have a model called Programme which has a translated attribute called summary.

When I enable sorting on that column I get an exception:

Mysql2::Error: Unknown column 'summary' in 'order clause': SELECT  `programmes`.* FROM `programmes`   ORDER BY `summary` desc LIMIT 30 OFFSET 0

I tried to sort by translations_summary which leads to a similar issue.

def index do
  column :title, sortable: false # fallback
  column :title, sortable: :title # exception
  column :title, sortable: :translations_title #exception
end

Curiously I can access the summary property of a given programme, but active_admin is not able to sort by this property. Is there a way to include(:translations) like in the following scope-definition example?

default_scope -> { order('programme_translations.title').includes(:translations) }

Updating record creates new translation records instead of updating them

I have simple application like this

have a model class model.rb

class Post < ActiveRecord::Base
active_admin_translates :title, :text do
validates_presence_of :title
end
end
And appropriate migration

class CreatePosts < ActiveRecord::Migration
def up
create_table :posts do |t|
t.timestamps
end
Post.create_translation_table! title: :string, text: :text
end

def down
drop_table :posts
Post.drop_translation_table!
end
end
Active admin page is configured like this

ActiveAdmin.register Post do
permit_params :title, :text, translations_attributes: [:title, :text, :locale]

index do
translation_status
default_actions
end

form do |f|
f.translated_inputs 'Translated fields', switch_locale: false do |t|
t.input :title
t.input :text
end
f.actions
end
end

When I try to update record, new translation records are created instead updating the old ones causing the AA to display the first value.

I also posted this as a question on Stack Overflow at http://stackoverflow.com/questions/23547401/activeadmin-globalize-does-not-update-records

Save empty translations

I have 4 translation in my site and 4 tabs for them. When I try create news for example with one translation and I save it it also create 3 another as "" strings.
How I can save just not void translations?

Delete empty translation records on save

Hi guys, first I want to say THX for this gem! It saved me ages, is good designed and a pleasure to work with.

Today I came up with something strange, which maybe also is interesting for you. There are also records created for empty languages (all fields empty). As I want to give the users the ability to switch languages (if there are any other available) its a hassle to find out, which languages are filled and which not.

So I implemented an easy solution. A before_filter which removes empty languages form the params hash, or marks empty languages which existed (has han id) with the flag '_destroy' => '1'. Where as the first part works greate. The second part with the '_destory' => '1' gets ignored. I don't know why, because you set allow_destroy: true

# activeadmin-globalize3 / lib / active_admin / globalize3 / active_record_extension.rb
attr_accessible :translations_attributes
accepts_nested_attributes_for :translations, allow_destroy: true 

Here my code:

# Inside an own active_admin page
ActiveAdmin.register MyModel do
  before_filter :remove_or_mark_empty_translations, :only => [:update, :create]

  controller do
    private
    def remove_or_mark_empty_translations
      params[:requisition][: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 { |k,v| v.empty? ? true : false }[2..-1]).include?(false)
          if t.last[:id].empty?
            # If id is also empty, remove from params
            # works fine!
            params[:requisition][:translations_attributes].delete(t.first)
          else
            # otherwise mark to destroy
            # FIXME : seems to be ignored
            params[:requisition][:translations_attributes][t.first]['_destroy'] = '1'
          end
        end
      end
    end
  end
end

Have you any ideas or better solutions?

PS: to remove empty translation rows improves also the view helper translation_status ;)

css not precompiled on heroku

When deploying to heroku, I get the following error:

ActionView::Template::Error (active_admin/active_admin_globalize3.css isn't precompiled)

I already added the following lines to my application.rb:

config.assets.enabled = true
config.assets.precompile += ['active_admin.css', 'active_admin.js', 'active_admin_globalize3.css']

But I still get the error above. Rails 3.2.13, Ruby 2.0.0

Unable to use translated_inputs with form partial

Hi, don't know if I'm using it correctly. Here is my code:

ActiveAdmin.register Carousel do
  form partial: 'form'
= semantic_form_for [:admin, @carousel] do |f|

  - f.translated_inputs "Translated fields" do |t|
    t.input :name
  = f.actions
undefined method `translated_inputs' for #<Formtastic::FormBuilder:0x007fe1eb3e3c10>

I can't use "translated_inputs" inside "has_many"

I've next code:

form do |f|
    f.semantic_errors *f.object.errors.keys
    f.inputs 'General' do
      f.input :active, :as => :boolean
      f.translated_inputs "Translated fields", switch_locale: false do |t|
        t.input :title
        t.input :description, :as => :text
      end
      f.has_many :images, display: :panel do |image|
        image.input :asset, :as => :file
        image.translated_inputs "globalize", switch_locale: false, display: :panel do |translate_image|
          translate_image.input :title
        end
      end
    end
    f.actions
  end

But the in the (html) result isn't exist "translate_image.input :title", is empty.

PD: sorry by my english.

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.