Skip to content

Date field gets deleted, is detected as datetime #3134

New issue

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

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

Already on GitHub? # to your account

Closed
sedubois opened this issue May 10, 2019 · 6 comments
Closed

Date field gets deleted, is detected as datetime #3134

sedubois opened this issue May 10, 2019 · 6 comments

Comments

@sedubois
Copy link
Contributor

sedubois commented May 10, 2019

Rails admin half of the time displays and allows to select a time, even for fields of type date and not datetime. This is what it sometimes shows (correct):

Screenshot 2019-05-10 at 11 51 53

But just when reloading the page, sometimes it shows this, apparently randomly:

Screenshot 2019-05-10 at 11 52 02

The same display issue applies to the edit page.

But more importantly, when editing the record, randomly the date gets deleted upon saving. So because of this, any time I edit a record, I need to go and check if the date was preserved, otherwise I need to go and enter it again (hoping I remember what the value was).

Using rails_admin 1.4.2 and DB schema:

  create_table "testimonials", force: :cascade do |t|
    ....
    t.date     "date"
  end

EDIT: the issue remains (and even gets worse) if the type is set explicitly in the config:

  config.model 'Testimonial' do
    list do
      ...
      field :date, :date
    end
  end

Even in that case the time is shown:

Screenshot 2019-05-10 at 11 44 33

But more importantly, in this case the date field then gets silently nullified every single time when the record is edited.

@sedubois sedubois changed the title Rails admin randomly detects date field as datetime Date field gets deleted, is detected as datetime May 10, 2019
@sedubois
Copy link
Contributor Author

I wonder if it somehow relates to the fact that every time the admin pages get rendered, they seem to randomly choose between the English and French locales available in the app (no idea how to fix that). Then the value might be rejected because the date format is different between both languages.

@mshibuya
Copy link
Member

A similar issue exists, could you take a look?
#2837

Basically, RailsAdmin does not change locale at all. It's your app's responsibility to set it up correctly.

@sedubois
Copy link
Contributor Author

Thanks, that seems to have been the issue.

@sedubois
Copy link
Contributor Author

sedubois commented Jun 6, 2019

Actually it hasn't. My locale still randomly loads in English/French, and randomly my date values get deleted when saving.

So this can stay closed, but because it's a duplicate of #3140.

@sedubois
Copy link
Contributor Author

sedubois commented Jun 6, 2019

This workaround seems to work (use same date format in both locales).

# config/locales/rails.en.yml
en:
  time:
    formats:
      long: "%Y-%m-%d %H:%M:%S"

# config/locales/rails.fr.yml
fr:
  time:
    formats:
      long: "%Y-%m-%d %H:%M:%S"

@Shaglock
Copy link

@sedubois Thank you for the workaround. I think after updating gems I started to get this issue, my date fields were just set to nil after editing anything, but your workaround helped me

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

No branches or pull requests

3 participants