jquery-ui-railsなるgemがあったのでそれを使う。
twitter-bootstrap-rails
が適用済みの状態。
インストール
Gemfile
group :assets do
gem 'jquery-ui-rails'
end
bundle install
設定
app/assets/javascripts/application.js
//= require jquery.ui.all
app/assets/stylesheets/application.css
*= require jquery.ui.all
とりあえず全てのウィジェットを使えるようにする。
使用するウィジェットのみ読み込むことも可能。
使い方
datepickerを使ってみる。
アプリケーション全体で使用したいのでbootstrap.js.coffee
にdatepickerを追記。
app/assets/javascripts/bootstrap.js.coffee
jQuery ->
$("a[rel=popover]").popover()
$(".tooltip").tooltip()
$("a[rel=tooltip]").tooltip()
$('#datepicker').datepicker()
viewを修正。
app/views/products/_form.html.erb
<%= f.text_field :name, :class => 'text_field', id: 'datepicker' %>
これで完了。以下のように表示される。