If I want to create a new rails gem that adds methods to Rails views what is the right way to do this? Is it to extend ActionView::Base? Would it involve ApplicationHelper in some way?
Asked
Active
Viewed 1,454 times
1 Answers
7
Many gem authors create a module that defines their view helper methods and then includes them in ActionView::Base
.
module MyGem
module ActionViewExtensions
module MyHelpers
def my_view_helper
# ...
end
end
end
end
# You can do this here or in a Railtie
ActionView::Base.send :include, MyGem::ActionViewExtensions::MyHelpers
Railtie method:
https://github.com/mynameisrufus/sorted/blob/master/lib/sorted/railtie.rb
Alternative:

Carlos Ramirez III
- 7,314
- 26
- 33