我是新来的铁轨,任何线索?如果你能建议我读什么也会更好。如何在rails中使用带有form_for的日期选择器?
我添加一个日期选择器插件到现有的rails4应用程序。我在Github上发现了this plugin。我遵循指示并在我的应用程序中配置了所有内容。参观http://localhost:3000/bookings/new看起来不错,但在我填写的信息并提交,出现错误:
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' %>
你想jQuery的日期选择器或下拉的年,月和日期? –
在你的'create'动作中,试试'@booking = Booking.new(booking_params)'。希望它有帮助。 – Zoran
@ user123我实施的是日期选择器,我可以选择日期和年份,在页面上看起来很好,而不是在我提交信息之后。 – Snailwalker