【发布时间】:2015-03-06 09:05:46
【问题描述】:
我到处搜索,我认为解决方案很简单,但我过于复杂了。
基本上我有一个具有以下属性的约会模型:
--- !ruby/object:Appointment
attributes:
id:
time:
user_id:
created_at:
updated_at:
时间:是一个日期时间属性
在控制器中,我有一个标准的创建操作:
class AppointmentsController < ApplicationController
def create
@appointment = Appointment.create(appointment_params)
current_user.appointment = @appointment
if @appointment.save
flash[:success] = "Appointment Booked!"
redirect_to appointments_path
else
redirect_to appointments_path
end
private
def appointment_params
params.require(:appointment).permit(:time, :test1, :test2)
end
end
在创建视图中,我有一个带有以下代码的表单:
<%= form_for(@appointment) do |f| %>
<div class="field">
<%= f.label :time %><br>
<%= f.datetime_select(:time, {start_year: 2015, end_year: 2016, start_hour: 9, end_hour: 18, minute_step: 60}) %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
现在这一切都保存得很好,可以做我想做的事,用户使用日期时间选择器创建约会,保存没有问题。
但是,当涉及到样式时,它变得很困难,因为我不知道如何分解 datetime_select。
我想要做的是使用我找到的 jQuery 日期时间选择器,但我不知道如何将参数传递给我的控制器,以便构建一个能够保存到 时间的日期时间: 属性
【问题讨论】:
-
我不明白你的问题,你想删除默认日历并使用 JQuery 日历吗?
-
嘿,如果这个问题让您感到困惑,对不起!基本上我想学习如何在不使用 rails 中的 datetime_select 帮助器的情况下建立一个日期时间。
-
你使用的是formtastic还是类似的?
-
不,正如您在代码中看到的那样,我只是使用 form_for 帮助器
标签: jquery ruby-on-rails ruby datetime form-for