将Ruby与HTML代码链接 [英] Linking Ruby with HTML Code

查看:243
本文介绍了将Ruby与HTML代码链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以通过在<script></script>标记之间插入代码来对HTML文档实施Javascript代码.是否有使用Ruby的类似方法?

I am aware that you can implement Javascript code to an HTML documents, by inserting the code between the <script></script> tags.. is there a similar way to do this with Ruby?

推荐答案

客户端Ruby(浏览器上是Ruby?!)

如果您的问题涉及在浏览器上执行Ruby代码,就像执行Javascript(不涉及服务器)一样,那么从传统意义上讲,这实际上是不可能的.

Client Side Ruby (Ruby on the browser?!)

If your question refers to executing Ruby code on the browser, like you would execute Javascript (the server isn't involved), than it's not really possible in the traditional sense.

但是, Opal 会将Ruby代码编译"为Javascript,从而允许您执行已编译的"Ruby"(现在javascript)代码,就像本机Javascript(有时甚至更好,因为Opal尝试优化您的代码).

However, Opal will "compile" your Ruby code into Javascript, allowing you to execute the compiled "Ruby" (now javascript) code within the browser, just like native Javascript (sometimes even better, as Opal attempts to optimize your code).

Ruby通常用于在服务器而非浏览器上运行代码.有很多解决方案.

Ruby is often used to run code on the server rather than the browser. There are a number of solutions.

例如,您可以使用ERB模板-这是 ERB的良好介绍-以及其他Ruby模板引擎(即令人惊叹的 Slim 模板引擎)以类似于PHP代码的方式运行Ruby代码(只会更易于编写和维护).

For example, you can use ERB templates - here's a good intro to ERB - as well as other Ruby template engines (i.e. the amazing Slim template engine) to run Ruby code in a similar way to PHP code (only easier to write and maintain).

但是,Ruby比简单模板要强大得多.有完整的针对Ruby编写的服务器和框架,使您可以使用非常强大的服务器端脚本.

However, Ruby is much more powerful than simple templates. There are whole servers and frameworks written in and for Ruby, allowing you very powerful server-side scripting.

常用框架:

  • Ruby on Rails 是许多初学者经常开始使用的非常常见的框架.

  • Ruby on Rails is a very common framework many beginners often start with.

Sinarta 也是一个很好的起点,通常受到经验丰富的编码人员的青睐,他们倾向于认为这是比Rails轻.

Sinarta is also a good starting point, usually favored by more experienced coders who tend to believe it's less heavy than Rails.

直接(无框架)使用机架是高性能的主流选择,但它需要更多知识.

Using Rack directly (with no framework) is the hi-performance mainstream choice, but it requires more knowledge.

阅读以下链接以获取更多的常见的Http- Web框架和基准.

Read the following link for more common Http-Web frameworks and Benchmarks.

还有更多的实验性或较不普遍的框架-通常着重于实时Web应用程序的框架,例如 Volt Plezi .

There are also more experimental, or less common, frameworks - usually ones focusing on real-time web applications, such as Volt and Plezi.

这篇关于将Ruby与HTML代码链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆