LoginSignup
39
40

More than 5 years have passed since last update.

Rails3.2.2でjQueryUIを使う

Posted at

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' %>

これで完了。以下のように表示される。

39
40
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
39
40