WebdevAlan
WebdevAlan

Reputation: 11

Using Bootstrap DatePicker in Rails scaffold form

I've got an auto-generated form from a scaffold model, and in the new.html.erb I can't add the DatePicker option to my date field (effective-date). Scaffold doesn't generate the form fields; it has just:

app/view/documents/new.html.erb:

<div class="row">
  <div class="col-md-6 col-md-offset-3">
    <%= render 'form', document: @document %>
        ** no fields here to customize **
    </div>
    <input type="text" id="TestDate" data-provide='datepicker' >
</div>

Model:

create_table "documents", force: true do |t|
    t.string    "docname"
    t.string    "description"
    t.string    "doctype"
    t.boolean   "renewal"
    t.date      "effective_date"
    t.date      "expiration_date"
    t.timestamp "created_at"
    t.timestamp "updated_at"
  end

TestDate does work.

Thanks in advance!

Upvotes: 0

Views: 442

Answers (2)

WebdevAlan
WebdevAlan

Reputation: 11

From the comment above I added my line of code in documents/_form.html.erb thusly:

<div class="field">
    <%= f.label :effectiveDate %>
     <input type="text" name="effectiveDate" id="effectiveDate" data-provide='datepicker'
  </div>

I took out the line that defined effectiveDate and replaced it with the datepicker line.

Upvotes: 0

Aashish
Aashish

Reputation: 807

Hi have you properly followed the steps? Follow the documentation. Or more precisely follow these steps:

1 Include bootstrap-datepicker-rails in Gemfile;

gem 'bootstrap-datepicker-rails'

2 Add this line to app/assets/stylesheets/application.css

 *= require bootstrap-datepicker
 # Or if using bootstrap v3:
 *= require bootstrap-datepicker3

3 Add this line to app/assets/javascripts/application.js

//= require bootstrap-datepicker

4 Use it like this

<input type="text" data-provide='datepicker>

Upvotes: 1

Related Questions