简体   繁体   English

Rails 3.2.3中的Twitter-Bootstrap

[英]Twitter-Bootstrap in Rails 3.2.3

Has anybody used twitter bootstrap and deployed application in production? 有人在生产中使用过Twitter Bootstrap并部署了应用程序吗? Can you direct me to some resources? 你能指导我一些资源吗? I watched railscasts but if there are any blogs which gives detail explanation. 我看过railscasts,但是否有博客提供详细说明。 Are there any other option for frontend other than twitter bootstrap? 除twitter bootstrap之外,前端还有其他选择吗? Also, is there any javascript option? 此外,是否有任何javascript选项?

Here's the thing: Bootstrap is not a front-end. 事情是这样的:Bootstrap不是前端。 It is a way to get started on the design of your site by creating a decent-looking starting point. 这是一种通过创建美观的起点来开始网站设计的方法。 It is mainly CSS (well, LESS) with a few optional JavaScript additions to add extra UI functionality. 它主要是CSS(当然是LESS),并添加了一些可选的JavaScript,以添加额外的UI功能。

If you're actually interested in building a front end to a Rails app, you may be interested in Backbone.js . 如果您实际上对构建Rails应用程序的前端感兴趣,则可能对Backbone.js感兴趣。 Backbone is a way to link up your HTML DOM with your data (from Rails), and is great for single-page apps which don't require page refreshes every time you do anything. 骨干网是一种将HTML DOM与数据(来自Rails)链接的方法,非常适合单页应用程序,该应用程序每次执行任何操作都不需要刷新页面。 A good starting place for learning Backbone is Code School's Anatomy of Backbone tutorials. 学习骨干的一个很好的起点是Code School的《骨干解剖》教程。 Coincidentally, Code School also offer many other courses you might like. 巧合的是,Code School还提供了许多您可能喜欢的其他课程。

To link CSS and JavaScripts to your view, you can use Asset Tag Helpers . 要将CSS和JavaScript链接到视图,可以使用Asset Tag Helpers

As an example: 举个例子:

<%= javascript_include_tag "bootstrap" %>
<%= stylesheet_link_tag "bootstrap" %>

would generate tags linking to bootstrap.js and bootstrap.css , if those are the names of the files. 如果这些是文件名,则会生成链接到bootstrap.jsbootstrap.css标签。

javascript_include_tag pulls scripts relative to app/assets/javascripts javascript_include_tag提取相对于app/assets/javascripts脚本
stylesheet_link_tag pulls stylesheets relative to app/assets/stylesheets stylesheet_link_tag相对于app/assets/stylesheets stylesheet_link_tag拉出样式app/assets/stylesheets

If you want to reference a file in a directory structure (ie assets are not in the root of the above folders), you can link relative to those root folders: 如果要引用目录结构中的文件(即资产不在上述文件夹的根目录中),则可以相对于这些根文件夹进行链接:

<%= javascript_include_tag "/bootstrap/bootstrap-min" %>
<%= stylesheet_link_tag "/bootstrap/bootstrap" %>

These tags would reference app/assets/javascripts/bootstrap/bootstrap-min.js and app/assets/stylesheets/bootstrap/bootstrap.css . 这些标记将引用app/assets/javascripts/bootstrap/bootstrap-min.jsapp/assets/stylesheets/bootstrap/bootstrap.css

To apply styles, you would then use the stylesheet classes and ids in bootstrap.css. 要应用样式,您将在bootstrap.css中使用样式表类和ID。 For instance, the button to fork Twitter's bootstrap looks like 例如,用于分叉Twitter引导程序的按钮看起来像

<a href="https://github.com/twitter/bootstrap/" 
   class="btn btn-primary btn-large">View project on GitHub</a>

You would use a URL Helper : 您将使用URL Helper

<%= link_to "View project on GitHub", 
             "https://github.com/twitter/bootstrap/", 
             :class => "btn btn-primary btn-large" %>

edit: 编辑:

If you are looking at the code on Github and confused about the .less extension, that is because Bootstrap uses a CSS generation framework called Less. 如果您在Github上查看代码并对.less扩展名感到困惑,那是因为Bootstrap使用了称为Less的CSS生成框架。 You'll need to run make bootstrap and be sure you have lessc installed. 您需要运行make bootstrap并确保已安装lessc Or, you can download the already compiled framework here . 或者,您可以在此处下载已编译的框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM