Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoMethodError: undefined method `halt_callback_chains_on_return_false=' for ActiveSupport:Module

I've been developing this RoR 5.1 application for a while, and I need to add a new migration now:

class AddActiveFlagToParameters < ActiveRecord::Migration[5.1]
  def change
    add_column :parameters, :is_active, :boolean, :default => true 
  end
end

When I try to run the migration, rails raises the error:

NoMethodError: undefined method `halt_callback_chains_on_return_false=' for ActiveSupport:Module

Reading around, I finally worked around the issue by upgrading to Rails 5.2 (gem activesupport 5.2.0) and commenting out the line in the file config/initializers/new_framework_defaults.rb

But this sounds like a short term solution.

Where does this come from? How can I safely handle this issue ?

like image 694
user1185081 Avatar asked Apr 10 '18 02:04

user1185081


People also ask

Why is halt_callback_chains_on_return_false not working in activesupport?

I guess the reason it raise this error because halt_callback_chains_on_return_false option is actually remove from ActiveSupport according to this release note. Show activity on this post.

Why is my helper module not working in rails?

That's fine, the helper module is not mandatory so Rails silences a load error. But it could be the case that the helper module does exist and in turn requires another library that is missing. In that case Rails must reraise the exception. The method is_missing?provides a way to distinguish both cases:

Is there a way to forward methods from an anonymous module?

though an anonymous module is unreachable by definition. Defined in active_support/core_ext/module/anonymous.rb. 3.4 Method Delegation 3.4.1 delegate The macro delegateoffers an easy way to forward methods. Let's imagine that users in some application have login information in the Usermodel but name and other data in a separate Profilemodel:


1 Answers

halt_callback_chains_on_return_false setting in the initializer was a solution for temporary keeping old callback behaviour after upgrade to Rails 5.0. Assumed that you need time to check all callbacks in the app and after it you can remove this setting. And assumed that on the upgrade to 5.2 all is already checked, so this setting is removed.

Before Rails 5, returning false from any before_ callback in ActiveModel or ActiveModel::Validations, ActiveRecord and ActiveSupport resulted in halting of callback chain.

Starting from Rails 5.0 if any before_ callback returns false then callback chain is not halted. To explicitly halt the callback chain, we need to use throw(:abort).

So you need to check all before_callbacks in the app for proper behaviour, change them if needed and remove this line from initializer after it.

You can read more here

like image 185
Vasilisa Avatar answered Sep 17 '22 14:09

Vasilisa