Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use date picker with form_for in rails?

I'm new to rails,Any clues ? and it would be better if you can suggest me what to read as well.

Im adding a date picker plugin into an existing rails4 app. i found this plugin on Github. i followed the instruction and configured everything in my app. Visiting http://localhost:3000/bookings/new looks fine, but after i fill up the information and submit it , error occurs :

ArgumentError in BookingsController#create
First argument in form cannot contain nil or be empty

booking_controller.rb:

def new
    @booking = Booking.new
  end

  def create
    @booking = current_user.bookings.build(booking_params)    # Not the final implementation!
    if @booking.save
      flash[:success] = "You have submited the information successfully!"
      redirect_to root_url
    else
      render 'static_pages/home'
    end
  end

new.html.rb

    <%= form_for (@booking) do |f| %>
    <%= render 'shared/errorbooking_messages' %>
      <%= f.label :date_of_tour %>
      <input data-provide="datepicker">

      <%= f.label :hotel_name %>
      <%= f.text_field :hotel_name, class: 'form-control' %>

      <%= f.label :hotel_address %>
      <%= f.text_field :hotel_address, class: 'form-control' %>
like image 578
gqli Avatar asked May 29 '15 06:05

gqli


1 Answers

Replace this input field

<input data-provide="datepicker">

by

<%= f.text_field :date_of_tour, "data-provide" => 'datepicker' %>

Hope it's helpful.

Just to build on this answer. As of rails 4 you can also use the following format.

<%= f.text_field :date_of_tour, data:{ provide:'datepicker' } %>
like image 87
Akshay Borade Avatar answered Oct 19 '22 04:10

Akshay Borade