Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing :locale fields in the new record #42

Open
modreoci opened this issue Jun 25, 2020 · 1 comment
Open

Missing :locale fields in the new record #42

modreoci opened this issue Jun 25, 2020 · 1 comment

Comments

@modreoci
Copy link

modreoci commented Jun 25, 2020

I did everything what is in the documentation properly. Everything seems to be OK. Records with the existing translations are updated correctly, but the new records (SQL commands) are without field :locale and cause the error message:
- Translations locale can't be blank

Here is the output (server log):

Started POST "/r_admin_321/event/new" for 127.0.0.1 at 2020-06-26 00:31:36 +0200
Processing by RailsAdmin::MainController#new as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"9PdkLD7qAHFUjXtkNHPVSOdcLT0gdSNfNXveFhmvqEkUA2CzbtY81zqMG4Gesvv/CdRNjsvhPVNOqb9QxfEAVw==", "event"=>{"link"=>"", "active"=>"0", "event_photo_ids"=>["", ""], "translations_attributes"=>{"0"=>{"name"=>"aaa", "perex"=>"", "description"=>""}, "1"=>{"name"=>"bbb", "perex"=>"", "description"=>""}}}, "_wysihtml5_mode"=>"1", "return_to"=>"http://fi.qq:3000/r_admin_321/event", "_save"=>"", "model_name"=>"event"}
  EventPhoto Load (0.9ms)  SELECT "event_photos"."id", "event_photos"."image", "event_photos"."position", "event_photos"."event_id", "event_photos"."created_at", "event_photos"."updated_at" FROM "event_photos" WHERE 1=0 ORDER BY "event_photos"."position" ASC
  ↳ /home/modreoci/.rvm/gems/ruby-2.6.5@skphccc2/gems/activerecord-5.2.4.2/lib/active_record/log_subscriber.rb:98
   (0.2ms)  BEGIN
  ↳ /home/modreoci/.rvm/gems/ruby-2.6.5@skphccc2/gems/activerecord-5.2.4.2/lib/active_record/log_subscriber.rb:98
   (0.2ms)  ROLLBACK

Here config/initialiters/rails_admin.rb

RailsAdmin.config do |config|

  config.included_models = ['Carousel','Carousel::Translation','Document','Document::Translation','Event','Event::Translation','EventPhoto','EventPhoto::Translation','Member','Member::Translation','Personality','Personality::Translation','Spotlight','Spotlight::Translation']

  config.actions do
    dashboard                     # mandatory
    index                         # mandatory
    new
    export
    bulk_delete
    show
    edit
    delete
    show_in_app

    ## With an audit adapter, you can add:
    # history_index
    # history_show
    nestable
  end

  config.model Carousel do
    nestable_list true
    configure :translations, :globalize_tabs
    exclude_fields :id, :position, :created_at, :updated_at
  end

  config.model 'Carousel::Translation' do
    visible false
    configure :locale, :hidden do
      help ''
    end
    include_fields :locale, :title
  end

  config.model Document do
    nestable_list true
    configure :translations, :globalize_tabs
    exclude_fields :id, :position, :created_at, :updated_at
  end

  config.model 'Document::Translation' do
    visible false
    configure :locale, :hidden do
      help ''
    end
    edit do
      field :name
      field :description, :wysihtml5
    end
    include_fields :locale, :name, :description, :slug
  end

  config.model Event do
    nestable_list true
    configure :translations, :globalize_tabs
    exclude_fields :id, :position, :created_at, :updated_at
  end

  config.model 'Event::Translation' do
    visible false
    configure :locale do
      help ''
    end
    edit do
      field :name
      field :perex
      field :description, :wysihtml5
    end
    include_fields :locale, :name, :perex, :description, :slug
  end

  config.model EventPhoto do
    nestable_list true
    configure :translations, :globalize_tabs
    exclude_fields :id, :position, :created_at, :updated_at
  end

  config.model 'EventPhoto::Translation' do
    visible false
    configure :locale, :hidden do
      help ''
    end
    edit do
      field :name
      field :description, :wysihtml5
    end
    include_fields :locale, :name, :description
  end

  config.model Member do
    nestable_list true
    configure :translations, :globalize_tabs
    exclude_fields :id, :position, :slug, :created_at, :updated_at
  end

  config.model 'Member::Translation' do
    visible false
    configure :locale, :hidden do
      help ''
    end
    edit do
      field :description, :wysihtml5
    end
    include_fields :locale, :description
  end

  config.model Personality do
    nestable_list true
    configure :translations, :globalize_tabs
    exclude_fields :id, :position, :slug, :created_at, :updated_at
  end

  config.model 'Personality::Translation' do
    visible false
    configure :locale, :hidden do
      help ''
    end
    edit do
      field :job_title
      field :role
      field :description, :wysihtml5
    end
    include_fields :locale, :job_title, :role, :description
  end
`
  config.model Spotlight do
    nestable_list true
    configure :translations, :globalize_tabs
    exclude_fields :id, :position, :slug, :created_at, :updated_at
  end

  config.model 'Spotlight::Translation' do
    visible false
    configure :locale, :hidden do
      help ''
    end
    edit do
      field :body, :wysihtml5
    end
    include_fields :locale, :body
  end

end

Here app/models/event.rb

class Event < ApplicationRecord
  default_scope -> { order(position: :asc) }
  has_many :event_photos, -> { order(position: :asc) }, :dependent => :nullify
  translates :name, :perex, :description, :slug
  accepts_nested_attributes_for :translations, allow_destroy: true
  acts_as_list top_of_list: 0
  translation_class.validates :name, presence: true
end

And finally the screenshot (both translations fields Name was correctly filled out):
obrázok

@Sankalp-Dwivedi
Copy link

Hi @modreoci, did you manage to get it work? I am facing the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants