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

Section 2.1: uninitialized constant ActionText::Engine::ApplicationController #9

Open
ToTenMilan opened this issue Sep 21, 2019 · 12 comments
Labels
rails update Issues that come up for newer versions of Rails

Comments

@ToTenMilan
Copy link

Rails 6.0.0

rails/rails#35749

app folder con not be removed entirely doing the book on Rails 6, since Zeitwerk autoloading expects app/controllers/application_controller.rb to be in place.

Without this file, error uninitialized constant ActionText::Engine::ApplicationController is raised while visiting root

@shageman
Copy link
Owner

shageman commented Oct 4, 2019

Thanks for letting everyone know!

@shageman shageman added the rails update Issues that come up for newer versions of Rails label Oct 4, 2019
@maurcarvalho
Copy link

There is any alternatives to work around and keep /app dir out?
I really liked the approach to not have an app place at all. Like you've said in the book: it sends a clear message.

@shageman
Copy link
Owner

I haven't found a way. We'll leave this issue open so that others coming across this can add to the conversation.

@cyberchinya
Copy link

Puma caught this error: uninitialized constant ActionText::Engine::ApplicationController (NameError)
/usr/local/lib/ruby/gems/2.7.0/gems/actiontext-6.0.2.1/lib/action_text/engine.rb:43:in block (2 levels) in <class:Engine>' /usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:429:in instance_exec'
/usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:429:in block in make_lambda' /usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:201:in block (2 levels) in halting'
/usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:607:in block (2 levels) in default_terminator' /usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:606:in catch'
/usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:606:in block in default_terminator' /usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:202:in block in halting'
/usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:514:in block in invoke_before' /usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:514:in each'
/usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:514:in invoke_before' /usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:134:in run_callbacks'
/usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/execution_wrapper.rb:119:in complete!' /usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/execution_wrapper.rb:76:in ensure in block in run!'
/usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/execution_wrapper.rb:76:in block in run!' /usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/execution_wrapper.rb:70:in tap'
/usr/local/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/execution_wrapper.rb:70:in run!' /usr/local/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/executor.rb:12:in call'
/usr/local/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/static.rb:126:in call' /usr/local/lib/ruby/gems/2.7.0/gems/rack-2.1.1/lib/rack/sendfile.rb:113:in call'

@ghost
Copy link

ghost commented Feb 17, 2020

#<NameError: uninitialized constant ApplicationController::DeviseWhitelist>
/home/djole/DjoloPortfolio/app/controllers/application_controller.rb:2:in <class:ApplicationController>' /home/djole/DjoloPortfolio/app/controllers/application_controller.rb:1:in

'

... and so on..
any idea how to fix it?

@shageman
Copy link
Owner

@djordje21 would you describe a bit more of what's going on in your app?

Are you using devise?
Did you delete the default application controller?
Are you creating DeviseWhitelist or is that something that's there by default?

@ghost
Copy link

ghost commented Feb 19, 2020

@shageman
It's my first app and I'm still learning how to fix the bugs and I fixed mine somehow.
Yes, I am using Devise, thanks for fast answer.

So, in my application_controller.rb :
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include DeviseWhitelist
include SetSource
end

then I went in my
devise_whitelist.rb :

module DeviseWhitelist
extend ActiveSupport::Concern

included do
	before_action :configure_permitted_parameters, if: :devise_controller?
end

  def configure_permitted_parameters
	 devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
	 devise_parameter_sanitizer.permit(:account_update, keys: [:name])
  end

end

At the moment when I post my comment i had instead of
before_action there was
before_filter
but before_filter didn't work, and that was the error message,

I just change it in before_action .

@shageman
Copy link
Owner

shageman commented Feb 19, 2020 via email

@mbjornson
Copy link

mbjornson commented Oct 12, 2020

I was able to work around this and the sprockets issues by updating config/application.rb to be

#require 'rails/all' require "rails" require "active_model/railtie" require "active_job/railtie" require "active_record/railtie" require "active_storage/engine" require "action_controller/railtie" require "action_mailer/railtie" require "action_mailbox/engine" #require "action_text/engine" require "action_view/railtie" require "action_cable/engine"
Is there anyway to load only what you need in the top level rails app, and then within each component/engine load only what you need there too? An example would be I wouldn't need Action Text in the top level rails app, but I do need it within certain engines/components?

@shageman
Copy link
Owner

@mbjornson interesting idea! I have never seen this but think it should be possible:

In the requires that you posted, and only what you know the main app needs. Then in a component and a require to additional stuff at the top of components/your-gem/lib/your-gem.rb

Generally this is the way in which you ensure that gems have access to all their external dependencies.

@mbjornson
Copy link

I'm also working in Rails 6 and got this and the sprockets error, so I've been trying to read as much as possible on engines and I suck at webpack to boot. The app that I'm thinking about using cbra approach is for a product I'm building. So I can't really go back to rails 5... I've been trying to go thru Spree, Devise and RefineryCMS's repos to see how they are approaching these two issues. I'm going to try to use the above approach to see how that works.

@mbjornson
Copy link

I started working through the book with a new Rails 5 app. No issues what so ever. I wonder how many of these issues are due to changes in Rails 6?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rails update Issues that come up for newer versions of Rails
Projects
None yet
Development

No branches or pull requests

5 participants