Skip to content

Commit

Permalink
Improve rails integration
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Oct 9, 2024
1 parent 3a2918c commit 6ede4f4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
8 changes: 1 addition & 7 deletions lib/datagrid.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "action_view"
require "datagrid/configuration"
require "datagrid/engine"

module Datagrid

Expand All @@ -14,14 +15,7 @@ module Datagrid
autoload :Configuration

autoload :Helper
::ActiveSupport.on_load(:action_view) do
ActionView::Base.send(:include, Datagrid::Helper)
end

autoload :FormBuilder
::ActiveSupport.on_load(:action_view) do
ActionView::Helpers::FormBuilder.send(:include, Datagrid::FormBuilder)
end

autoload :Renderer

Expand Down
6 changes: 4 additions & 2 deletions lib/datagrid/engine.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
require "rails/engine"
require 'datagrid/helper'
require 'datagrid/form_builder'

module Datagrid
# @!private
class Engine < ::Rails::Engine
initializer "datagrid.helpers" do
#TODO: check why it doesn't work
ActiveSupport.on_load :action_view do
include Datagrid::Helper
ActionView::Base.send(:include, Datagrid::Helper)
ActionView::Helpers::FormBuilder.send(:include, Datagrid::FormBuilder)
end
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/datagrid/helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require "datagrid/engine"
require "action_view"

module Datagrid
Expand Down

0 comments on commit 6ede4f4

Please sign in to comment.