Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4640

Rails Overriding Gem Controllers

$
0
0

I am working with a gem in my Rails app that has a controller located in <gem_root>/app/controllers/<gem_name>/things_controller.rb. I need to override (more specifically, extend) one of the actions in this controller. I have created a file at <rails_root>/app/controller/<gem_name>/things_controller.rb. RubyMine can see the original ThingsController and suggests it in auto-completions, but I cannot get the Ruby interpreter to override it:

# <rails_root>/app/controllers/<gem_name>/things_controller.rbGemName::ThingsController.class_eval do  def new    super    # My code to extend super  endend

This results is an unitialized constant error:

uninitialized constant GemName::ThingsController

I have even tried copying the gem into vendor/ and directly requiring the original file at the top of the override file, but this doesn't fix the issue. I am used to working with gems that have code in lib/ but not gem members in app/. It seems that app/ isn't exposed to the host app by default. How do I override this controller?


Viewing all articles
Browse latest Browse all 4640

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>