Я решил эту проблему, добавив в файл adminlte js. $(document).on('turbolinks:load',function(){...})
ниже приведен код, в котором я заменил $ (window) .on ('load') на $ (document) .on ('turbolinks: load) внутри js-файла adminlte, функция Tree ()
$ (document) .on ('turbolinks: load', function () {$ (Selector.data) .each (function () {Plugin.call ($ (this));});} );
def define_singleton_method_by_proc(obj, name, block)
metaclass = class << obj; self; end
metaclass.send(:define_method, name, block)
end
p = proc { "foobar!" }
define_singleton_method_by_proc(y, :bar, p)
или, если вы хотите сделать monkey-patch для Object, чтобы упростить его
class Object
# note that this method is already defined in Ruby 1.9
def define_singleton_method(name, callable = nil, &block)
block ||= callable
metaclass = class << self; self; end
metaclass.send(:define_method, name, block)
end
end
p = proc { "foobar!" }
y.define_singleton_method(:bar, p)
#or
y.define_singleton_method(:bar) do
"foobar!"
end
, или, если вы хотите определить свой встроенный процесс, это может быть более читабельным
class << y
define_method(:bar, proc { "foobar!" })
end
или,
class << y
define_method(:bar) { "foobar!" }
end
это наиболее читаемый, но, вероятно, не соответствует вашим потребностям
def y.bar
"goodbye"
end
You can use the syntax class <
str1 = "Hello"
str2 = "Foo"
class <<str1
def to_spanish
'Hola'
end
end
Now if you do str1.to_spanish
, it will return "Hola", but str2.to_spanish
will give you a NoMethodFound exception.