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

uninitialized constant Formtastic::I18n::SCOPES #5939

Closed
afuno opened this issue Nov 19, 2019 · 4 comments
Closed

uninitialized constant Formtastic::I18n::SCOPES #5939

afuno opened this issue Nov 19, 2019 · 4 comments

Comments

@afuno
Copy link

afuno commented Nov 19, 2019

Rails 6.0.1, Puma 4.3.0, Devise 4.7.1, ActiveAdmin 2.4.0, Formtastic 3.1.5


Once again I am creating a Rails application. Created the foundation. A couple of models. Made a simple front-end for them. Next install Devise, ActiveAdmin.

In general, nothing unusual. Locally everything works fine.

But on the server, some kind of nonsense began to happen with ActiveAdmin.

In general, the application on the server is working fine. Through the console, I can create all the data. These data are successfully displayed on the site.

But if I go into ActiveAdmin...

Dashboard page displayed successfully. But if I go to the index page of any entity, then I will get the following error (from the log):

2019-11-19T00:55:04.216309411Z app[web.1]: web| I, [2019-11-19T00:55:04.198819 #14]  INFO -- : [9ac98910-3a38-496d-9f5e-f276bc590ba7]   Rendered vendor/bundle/ruby/2.5.0/gems/activeadmin-2.4.0/app/views/active_admin/resource/index.html.arb (Duration: 73.2ms | Allocations: 17729)
2019-11-19T00:55:04.216369240Z app[web.1]: web| I, [2019-11-19T00:55:04.199305 #14]  INFO -- : [9ac98910-3a38-496d-9f5e-f276bc590ba7] Completed 500 Internal Server Error in 86ms (ActiveRecord: 5.8ms | Allocations: 19675)
2019-11-19T00:55:04.216376506Z app[web.1]: web| F, [2019-11-19T00:55:04.203841 #14] FATAL -- : [9ac98910-3a38-496d-9f5e-f276bc590ba7]
2019-11-19T00:55:04.216380926Z app[web.1]: web| [9ac98910-3a38-496d-9f5e-f276bc590ba7] ActionView::Template::Error (uninitialized constant Formtastic::I18n::SCOPES
2019-11-19T00:55:04.216385058Z app[web.1]: web| Did you mean?  Sprockets):
2019-11-19T00:55:04.216388027Z app[web.1]: web| [9ac98910-3a38-496d-9f5e-f276bc590ba7]     1: insert_tag renderer_for(:index)

The entire log: https://pastebin.com/raw/buWSveBZ

Only one section for entities works - this is the show action. Only two actions for entities work - these are show and destroy. Everyone else catches the error that I showed above.

I absolutely don't understand what's the matter.

I successfully use the identical config/initializers/active_admin.rb file in two other Rails 6 applications. Below I will show an example of one of the file for ActiveAdmin:

# frozen_string_literal: true

ActiveAdmin.register User do
  menu priority: 5

  permit_params :email, :full_name, :roles, :password, :password_confirmation

  remove_filter :users_roles

  controller do
    def find_resource
      scoped_collection.find_by!(pkey: params[:id])
    end
  end

  index do
    selectable_column
    id_column
    column :pkey
    column :email
    column :full_name
    column :roles
    column :current_sign_in_at
    column :sign_in_count
    column :created_at
    actions
  end

  form do |f|
    f.inputs do
      f.input :email
      f.input :full_name
      f.input :roles
      f.input :password
      f.input :password_confirmation
    end
    f.actions
  end
end

I'm hope for your help.

@afuno
Copy link
Author

afuno commented Nov 19, 2019

I added this line to all files:

config.filters = false

And this partially solved the problem. Now I can see the index page. But I can't add anything:

2019-11-19T11:40:26.628699181Z app[web.1]: web| I, [2019-11-19T11:40:26.628345 #15]  INFO -- : [febb0f9d-5c79-4bb8-a65c-9c2d8aac65fe]   Rendered vendor/bundle/ruby/2.5.0/gems/activeadmin-2.4.0/app/views/active_admin/resource/new.html.arb (Duration: 20.6ms | Allocations: 7361)
2019-11-19T11:40:26.628848171Z app[web.1]: web| I, [2019-11-19T11:40:26.628615 #15]  INFO -- : [febb0f9d-5c79-4bb8-a65c-9c2d8aac65fe] Completed 500 Internal Server Error in 36ms (ActiveRecord: 1.7ms | Allocations: 13293)
2019-11-19T11:40:26.631591018Z app[web.1]: web| F, [2019-11-19T11:40:26.631278 #15] FATAL -- : [febb0f9d-5c79-4bb8-a65c-9c2d8aac65fe]
2019-11-19T11:40:26.631646623Z app[web.1]: web| [febb0f9d-5c79-4bb8-a65c-9c2d8aac65fe] ActionView::Template::Error (uninitialized constant Formtastic::I18n::SCOPES
2019-11-19T11:40:26.631651169Z app[web.1]: web| Did you mean?  Sprockets):
2019-11-19T11:40:26.631657392Z app[web.1]: web| [febb0f9d-5c79-4bb8-a65c-9c2d8aac65fe]     1: insert_tag renderer_for(:new)
2019-11-19T11:40:26.631661649Z app[web.1]: web| [febb0f9d-5c79-4bb8-a65c-9c2d8aac65fe]
2019-11-19T11:40:26.631665171Z app[web.1]: web| [febb0f9d-5c79-4bb8-a65c-9c2d8aac65fe] app/admin/things.rb:27:in `block (3 levels) in <top (required)>'
2019-11-19T11:40:26.631851503Z app[web.1]: web| [febb0f9d-5c79-4bb8-a65c-9c2d8aac65fe] app/admin/things.rb:26:in `block (2 levels) in <top (required)>'

25 to 32 lines:

form do |f|
  f.inputs do         # <- 26
    f.input :title    # <- 27
    f.input :code
    f.input :link
  end
  f.actions
end

The same situation with User (for edit):

ctive_admin/resource/edit.html.arb (Duration: 53.4ms | Allocations: 7817)
2019-11-19T11:45:40.857019383Z app[web.1]: web| I, [2019-11-19T11:45:40.856770 #15]  INFO -- : [d2b8aa77-2a7a-4ed3-a392-8d7dd3f42a84] Completed 500 Internal Server Error in 77ms (ActiveRecord: 9.6ms | Allocations: 10430)
2019-11-19T11:45:40.861763024Z app[web.1]: web| F, [2019-11-19T11:45:40.861450 #15] FATAL -- : [d2b8aa77-2a7a-4ed3-a392-8d7dd3f42a84]
2019-11-19T11:45:40.861838528Z app[web.1]: web| [d2b8aa77-2a7a-4ed3-a392-8d7dd3f42a84] ActionView::Template::Error (uninitialized constant Formtastic::I18n::SCOPES
2019-11-19T11:45:40.861941126Z app[web.1]: web| Did you mean?  Sprockets):
2019-11-19T11:45:40.861954336Z app[web.1]: web| [d2b8aa77-2a7a-4ed3-a392-8d7dd3f42a84]     1: insert_tag renderer_for(:edit)
2019-11-19T11:45:40.861983566Z app[web.1]: web| [d2b8aa77-2a7a-4ed3-a392-8d7dd3f42a84]
2019-11-19T11:45:40.862399247Z app[web.1]: web| [d2b8aa77-2a7a-4ed3-a392-8d7dd3f42a84] app/admin/users.rb:31:in `block (3 levels) in <top (required)>'
2019-11-19T11:45:40.862450633Z app[web.1]: web| [d2b8aa77-2a7a-4ed3-a392-8d7dd3f42a84] app/admin/users.rb:30:in `block (2 levels) in <top (required)>'

29 to 36 lines:

form do |f|
  f.inputs do             # <- 30
    f.input :email        # <- 31
    f.input :full_name
    f.input :roles
  end
  f.actions
end

If necessary, I can invite an ActiveAdmin team member to my project repository.

@afuno
Copy link
Author

afuno commented Nov 19, 2019

If I delete this code:

form do |f|
  f.inputs do
    f.input :title
    f.input :code
    f.input :link
  end
  f.actions
end

I still can't add anything.

Now in the logs it will be:

2019-11-19T11:53:13.266218397Z app[web.1]: web| I, [2019-11-19T11:53:13.265840 #15]  INFO -- : [e86882f5-4932-4535-89f3-a3f42946de84]   Rendered vendor/bundle/ruby/2.5.0/gems/activeadmin-2.4.0/app/views/active_admin/resource/new.html.arb (Duration: 17.9ms | Allocations: 7646)
2019-11-19T11:53:13.266269605Z app[web.1]: web| I, [2019-11-19T11:53:13.266132 #15]  INFO -- : [e86882f5-4932-4535-89f3-a3f42946de84] Completed 500 Internal Server Error in 36ms (ActiveRecord: 3.0ms | Allocations: 13932)
2019-11-19T11:53:13.269593277Z app[web.1]: web| F, [2019-11-19T11:53:13.268343 #15] FATAL -- : [e86882f5-4932-4535-89f3-a3f42946de84]
2019-11-19T11:53:13.269621909Z app[web.1]: web| [e86882f5-4932-4535-89f3-a3f42946de84] ActionView::Template::Error (uninitialized constant Formtastic::I18n::SCOPES
2019-11-19T11:53:13.269625865Z app[web.1]: web| Did you mean?  Sprockets):
2019-11-19T11:53:13.269630851Z app[web.1]: web| [e86882f5-4932-4535-89f3-a3f42946de84]     1: insert_tag renderer_for(:new)

Log in full: https://pastebin.com/raw/pMucjedh

@afuno
Copy link
Author

afuno commented Nov 19, 2019

In the console on the server. In the container of the running application.

Formtastic::I18n::SCOPES
=> ["%{model}.%{nested_model}.%{action}.%{attribute}", "%{model}.%{nested_model}.%{attribute}", "%{nested_model}.%{action}.%{attribute}", "%{nested_model}.%{attribute}", "%{model}.%{action}.%{attribute}", "%{model}.%{attribute}", "%{attribute}"]

@afuno
Copy link
Author

afuno commented Nov 19, 2019

Can someone explain to me what it was?

I added these puts:

controller do
  puts
  puts
  puts Formtastic::I18n.inspect
  puts Formtastic::I18n::SCOPES.inspect
  puts
  puts

  def find_resource
    scoped_collection.find_by!(code: params[:id])
  end
end

That is, initially the controller was like this:

controller do
  def find_resource
    scoped_collection.find_by!(code: params[:id])
  end
end

And there is no more problem! What the hell is this? :D
I didn't do anything. Just added puts with the output of the constant SCOPES.

In the next deployment I deleted these puts. And the error reappears!

@javierjulio javierjulio closed this as not planned Won't fix, can't repro, duplicate, stale Mar 12, 2023
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