Ruby-on-rails (Rails)什么是“RJS”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/459647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
(Rails) What is "RJS"?
提问by Ethan
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?
我在博客文章和教程中看到了“RJS”和“RJS 模板”。我进行了搜索,但我仍然不确定。它是特定于 Rails 的技术,而不是像 JSON 或 YAML 这样的标准吗?
I understand it's used for "generating JavaScript." Does it generate generic JS or Rails-specific JS requiring the Prototype and Scriptaculous libraries?
我知道它用于“生成 JavaScript”。它是否生成需要 Prototype 和 Scriptaculous 库的通用 JS 或特定于 Rails 的 JS?
采纳答案by Rich Apodaca
This Railscastgives a nice example of using RJS to add and remove form fields dynamically without hitting the server with an ajax call.
这个 Railscast给出了一个很好的例子,它使用 RJS 动态添加和删除表单字段,而无需通过 ajax 调用访问服务器。
These RJS tipsmay also be helpful.
这些 RJS 技巧也可能有所帮助。
回答by MattMcKnight
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.
RJS 是一个模板(类似于 html.erb 文件),它生成 JavaScript,由浏览器在 eval 块中执行以响应 AJAX 请求。它有时(错误地?)用于描述 Rails 提供的 JavaScript、Prototype 和 Scriptaculous Helpers。
回答by Nicolas Maloeuvre
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.
RJS 是一个“ruby-to-js”模板系统,RJS 在 Rails 生态系统中不再广泛使用。现在首选 SJR(服务器生成的 JavaScript 响应)。
This DHH's post helped me a lot to understand : https://signalvnoise.com/posts/3697-server-generated-javascript-responses
这个 DHH 的帖子帮助我理解了很多:https: //signalvnoise.com/posts/3697-server-generated-javascript-responses

![Ruby-on-rails 没有路由匹配 [GET]](/res/img/loading.gif)