scarfacedeb / rails_admin_globalize_field

Tabbed interface and custom field type for globalize translations for Rails_admin
MIT License
51 stars 61 forks source link

Fields to be translated appear above tabs #1

Closed nonsense closed 11 years ago

nonsense commented 11 years ago

I am having troubles making the gem work with Rails 4 and RailsAdmin 0.5.0

I have an Article model:

class Article < ActiveRecord::Base
  belongs_to :user
  attr_accessible :content, :summary, :title, :user_id

  translates :content, :title, :summary, :versioning => true
  accepts_nested_attributes_for :translations, :allow_destroy => true

  has_paper_trail
end

rails_admin.rb initialiser consists of:

  config.included_models = ['Article','Article::Translation']

  config.model 'Article::Translation' do
    visible false
    configure :locale, :hidden
    include_fields :locale, :title, :summary, :content
  end

Any ideas what could be wrong? screen shot 2013-10-16 at 11 14 14 pm

scarfacedeb commented 11 years ago

Hi, Anton. thanks for the reporting.

I created a test app with roughly the same gems that you used - rails_admin, globalize3, paper_trail. I noticed that you still use attr_accessible macros. So, I added protected_attributes gem as well.

I couldn't reproduce your particular bug, but I noticed this warning in the console output:

WARNING: Can't mass-assign protected attributes for Article::Translation: locale

This warning causes tabs to stay hidden, but I can see them in the page source code.

When I added this code into Article.rb, tabs reappeared:

class Article::Translation
  attr_accessible :locale
end

Could you check the page source code to see if tabs content is there, hidden? Also, it would be helpful for me to see this source code, could you provide it to me?

nonsense commented 11 years ago

screen shot 2013-10-17 at 5 55 05 pm Hi Andrew,

Thanks for the quick response!

After reading your comment, I decided to start from scratch and not to include protected_attributes.

It appears this was part of the issue, but now I have another problem - the fields appear inside Translations, but are also duplicated for the current locale above Translations, which is weird. This is not the case with your screenshots...

The repository is at: http://github.com/nonsense/disaster

Thanks, Anton

nonsense commented 11 years ago

I ended up doing:

  rails_admin do
    edit do
      field :user
      field :translations
    end
  end

inside my Article model. Is this how I am supposed to hide the duplicate fields, or I am doing something wrong?

Thanks, Anton

scarfacedeb commented 11 years ago

I've probably found the cause of duplicated fields.

You have 2 sets of the same fields: inside the articles table and inside the article_translations table. (thus, you have 2 migrations 20131017153746_create_articles.rb and 20131017154123_translates_articles.rb that create these fields).

Therefore, rails_admin gives you that fields line this:

You don't need to add rails_admin configuration for Article model by default, but usually I just use include_fields method that helps to reorder the fields as I need it.

nonsense commented 11 years ago

Thanks a lot Andrew! That solves it all. I guess these issues were due to me using rails i18n for the first time, and not your gem :) I am marking as resolved now!

scarfacedeb commented 11 years ago

No problem!