我是Rails的新手。 我一直在我的Rails4应用程序中使用bootstrap-timepicker-rails gem,但它不起作用。 https://github.com/tispratik/bootstrap-timepicker-rails
的Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
gem 'twitter-bootstrap-rails'
gem 'bootstrap-timepicker-rails'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
的application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-timepicker
//= require_tree .
//= require_self
$('.t_picker').timepicker()
application.css
*= require_self
*= require bootstrap-timepicker
*= require_tree .
/event/_form.html.erb
<%= form_for(@event) do |f| %>
<% if @event.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@event.errors.count, "error") %> prohibited this event from being saved:</h2>
<ul>
<% @event.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :location %><br>
<%= f.text_field :location %>
</div>
<div class="field">
<%= f.fields_for :schedules do |sch| %>
<%= sch.time_field :start %>
<%= sch.time_field :end %>
<%= sch.text_field :description %>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
答案 0 :(得分:2)
我不知道你是否仍然需要这个,但我通过使用'模态'模板&amp;使我的工作(Rails 4应用程序)具体设置我的字段的ID,如下所示:
=f.input :time, as: :string, input_html: { class: 'bootstrap-timepicker', :id => 'time'}
&安培;在脚本中,像这样:
$('#time').timepicker({
minuteStep: 15,
etc etc..
希望有所帮助:)
答案 1 :(得分:0)
尝试更改此内容:
<%= sch.time_field :start %>
<%= sch.time_field :end %>
到此:
<%= sch.time_field :start, class: 't_picker' %>
<%= sch.time_field :end, class: 't_picker' %>
也许会有所帮助。