What is therubyracer or libv8 for in a rails application?

北城以北 提交于 2020-01-02 02:12:18

问题


I was working on a project and was having issues with therubyracer and libv8 often, so i decided to remove them. It seemed to be the only thing that used them as a dependency was less-rails which I wanted to remove anyways.

My main question is what are they for and do I need them in the average application and if so why?


回答1:


There are a few things for which a Rails app might use a Javascript Runtime:

1) The Rails Asset Pipeline requires a Javascript Runtime in order to perform Javascript compression.

2) Certain Rails ActionView Helpers like javascript_include_tag require a Javascript Runtime in order to execute Javascript functions.

Not every Rails application use those features, hence the reason that therubyracer gem is initially commented out in your Gemfile; Furthermore note that you could alternatively use NodeJS as your Javascript runtime.

For details, see:

http://guides.rubyonrails.org/asset_pipeline.html#javascript-compression

http://www.rubydoc.info/docs/rails/ActionView/Helpers/JavaScriptHelper

http://www.rubydoc.info/docs/rails/ActionView%2FHelpers%2FAssetTagHelper%3Ajavascript_include_tag

Proper "Rails" way to perform javascript on specific pages




回答2:


rubyracer provides following features:

 1. We can write your ruby codes inside js codes. 
 2. We can invoke the js functions from ruby codes.  
 3. Manipulation of javscript objects & the passing them to javascript functions.

Those are the few basic benefits of using rubyracer gem. Please read complete details here



来源:https://stackoverflow.com/questions/27934178/what-is-therubyracer-or-libv8-for-in-a-rails-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!