(Rails) What is “RJS”?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 22:36:32

问题


I've seen "RJS" and "RJS templates" mentioned in passing in blog posts and tutorials. I did a search, but I'm still unsure about it. Is it a technology specific to Rails, rather than a standard like JSON or YAML?

I understand it's used for "generating JavaScript." Does it generate generic JS or Rails-specific JS requiring the Prototype and Scriptaculous libraries?


回答1:


This Railscast gives a nice example of using RJS to add and remove form fields dynamically without hitting the server with an ajax call.

These RJS tips may also be helpful.




回答2:


RJS is a template (similar to an html.erb file) that generates JavaScript which is executed in an eval block by the browser in response to an AJAX request. It is sometimes used (incorrectly?) to describe the JavaScript, Prototype, and Scriptaculous Helpers provided by Rails.




回答3:


RJS was a "ruby-to-js" template system, RJS is not widely used anymore in the Rails ecosystem. SJR (Server-generated JavaScript Responses) is now prefered.

This DHH's post helped me a lot to understand : https://signalvnoise.com/posts/3697-server-generated-javascript-responses



来源:https://stackoverflow.com/questions/459647/rails-what-is-rjs

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