Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plugin to extend actioncontroller for rails

I am writing my first ever plugin for rails. The plugin is supposed to extend the actioncontroller::base

so after going through the tutorials here is what i did...

# Foo
class << ActionController::Base
  def function_name

assuming the plugin is called foo... but when i call function_name from an action, nothing happens... It seems the function_name is not even called. there is no method missing error either so i am sure the plugin has been loaded too...

m stuck real bad!

like image 490
Amit Avatar asked Jun 17 '26 18:06

Amit


1 Answers

You should do this via an on_load hook:

ActiveSupport.on_load(:action_controller) do
  include Foo
end

This will defer including the module until ActionController::Base would be loaded normally. This will avoid AC::Base from being prematurely loaded, which can save some load time in many Rake tasks and when loading the console.

like image 177
Yehuda Katz Avatar answered Jun 19 '26 13:06

Yehuda Katz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!