I'm working on porting a JS library to rails. This will be my first gem that I'm attempting to create and I seem to have run into a bit of a snag.
我正在努力将JS库移植到rails。这将是我尝试创建的第一个宝石,我似乎遇到了一些障碍。
The issue that I have is that there will necessarily be some JavaScript elements to the gem. However, I seem to be unable to find out how to do this.
我遇到的问题是gem必然会有一些JavaScript元素。但是,我似乎无法找到如何做到这一点。
Example:
例:
/lib/rotrails.rb
/lib/rotrails.rb
module RotRails
def self.isSupported
#Call JS function "isSupported() in /vendor/assets/javascript/rotrails.js
end
end
/vendor/assets/javascript/rotrails.js
/vendor/assets/javascript/rotrails.js
Function isSupported() {
return !!(document.createElement("canvas").getContext && Function.prototype.bind);
}
Any assistance on how to solve this problem as well as pass the result back to the Rails Gem would be appreciated.
任何有关如何解决此问题以及将结果传递回Rails Gem的帮助将不胜感激。
Update: To clarify, the rails part is logic calculations and the JavaScript is the frontend for the program. I am looking for the most logical way to have the two communicate or a reference to how to work with JavaScript when creating gemfiles.
更新:为了澄清,rails部分是逻辑计算,JavaScript是程序的前端。我正在寻找最合乎逻辑的方式来进行两者沟通,或者在创建gemfiles时参考如何使用JavaScript。
Thanks!
谢谢!
1 个解决方案
#1
0
Did you consider to use (or simply try) https://rails-assets.org/ instead of porting your js library manually ?
您是否考虑过使用(或只是尝试)https://rails-assets.org/而不是手动移植您的js库?
#1
0
Did you consider to use (or simply try) https://rails-assets.org/ instead of porting your js library manually ?
您是否考虑过使用(或只是尝试)https://rails-assets.org/而不是手动移植您的js库?