19e786a2a74377ff6e052d87fd8d1fa8

使用 Simple Form 結合 Bootstrap Form

2011-12-05 21:32:10 +0800xditeGem 節點 中發起
最後由 huacnlee2012-04-19 21:12:17 +0800回應 , 1387次閱讀

Ruby Taiwan Group 用的 CSS Framework 就是現在最熱門的 Bootstrap http://twitter.github.com/bootstrap/

不過因為 Bootstrap 有自己的 DOM 結構,如果使用內建的 form_for ,還是自己要再外面包一層 div,看起來還是很黏膩。

而 simple_form 也沒有辦法解決這一點,因為 Bootstrap 結構不太一樣。

於是後來就有人拉了這一個 pull request 實作出來了。
http://github.com/plataformatec/simple_form/pull/312

不過以上都不是重點。

==== 廢話結束分隔線

現在 Simple Form 要支援 Bootstrap Form 相當簡單。

只要使用 最新 trunk 的 simple_for,並往你專案底下的 config/initailizers/simple_form.rb 內一扔以下這個檔案。

http://github.com/rafaelfranca/simple_form-bootstrap/blob/master/config/initializers/simple_form.rb

然後這樣使用 form

<%= simple_form_for @article, :wrapper => :inline do |f| %>

就可以輕鬆使用了...

而 simple_form 作者 Jose Valim 也在 twitter 上宣布 2.0 將會預設加入 bootstrap built-in support feature。
http://twitter.com/#!/josevalim/status/143629690102493184

並發表了 simple_form 2.0 升級指南

http://twitter.com/#!/josevalim/status/143629690102493184

====

如果你還是不知道怎麼用。歡迎 clone 本站程式碼下來看
http://github.com/rubytaiwan/ruby-taiwan

截至 2012-04-19 21:12:17 +0800,共收到 9 條回應
A7c2a1ef345d950bf80223bc112d93b6
weijenlu 1樓, 於2011-12-05 22:09:08 +0800回應

還不賴耶。

4f6b8ae2c5392eb9df6bfc1e5ab04079
congteng 2樓, 於2011-12-07 22:10:47 +0800回應

支持一个.. 刚是你给我在ruby-china回复得..我在这里找到详细解答了 :)

53635a1ff7e701630b201f2bbd652db3
kevin 3樓, 於2011-12-08 22:49:09 +0800回應

很不错,学习啦。

146e61322cc18f833dddf394ba99e478
zernel 4樓, 於2011-12-08 23:17:46 +0800回應

学习了

55862f8fd6004cabfef8a8f1cc09b1ec
bjack617 5樓, 於2011-12-09 15:00:45 +0800回應

剛好最近也在用 Bootstrap, 剛好可以派上用場,受益良多

Fd779852eb8e519999f8b35c47777608
chiayi 6樓, 於2011-12-17 19:01:03 +0800回應

這個太贊了!

B25df49ad3ddf0cc833eb93ebeda285c
pobeike 7樓, 於2011-12-18 21:43:56 +0800回應

凑个脸熟XD

009994c3985985809d2d644bd49aa1c2
lulalala 8樓, 於2012-04-19 14:22:52 +0800回應

:wrapper => :inline

應該是

:wrapper => :bootstrap

4035ddfe11dbb2afc4e683b1bc6ac68f
huacnlee 9樓, 於2012-04-19 21:12:17 +0800回應

:inline 这个参数就不应该加上

需要 登入 後方可回應,如果你還沒有帳號按這裡 註冊