Rails Rails 中使用 helper 生成标签如何指定 css

congteng · 2011年12月07日 · 最后由 shanks 回复于 2012年10月21日 · 3742 次阅读

知道 ruby-china 使用了 bootstrap.但是查看源码却找不到显示引用得地方..

不明白,如果使用类似

<%= link_to "xxx"%>
<%= text_field "xxx"%>
...

得 helper 快速生成 html 标签时如何给该标签加入 css 样式..?

难道都要在引用 css 文件里 给生成得标签一一去定义吗?

link_to(body, url, html_options = {})
# url is a String; you can use URL helpers like
# posts_path

html_options = {}可以配置 a 标签里面的各种属性。

比如

link_to "某某","/your_url",:class=>"your_link_css"

Rails 3.1 + Ham + Bootstrap 重写的 Rails 3 Tutorial Sample App,欢迎围观 https://github.com/southwolf/sample-revision

PS Rails3Tutorial 还算是不错的入门教程…… http://ruby.railstutorial.org/

你是指?

<%= link_to("xxx", post_path, :class => "box") %>

另外回復 bootstrap 的 form 問題,現在 ruby-china 是使用 simple_for 加上 bootstrap 的 template ( simple_form trunk feature )

這樣直接使用

<%= f.input :xxx, :as => "text", :input_html => { :class => "xxxlarge" } ) %>

會自動轉成 simple_form 那樣複雜的 DOM 去包覆...

不必再自己寫一堆東西

谢谢以上回答。 #3 楼 @xdite 刚了解了一下 simple_form..问题已经搞明白了 谢谢

需要 登录 后方可回复, 如果你还没有账号请 注册新账号