我有以下HAML表格:
.row
.col-lg-6
.panel.panel-default
.panel-heading
%h1.box-title
%i.fa.fa-calendar.fa-fw
Availability
.panel-body
= form_tag dashboard_kid_availabilities_url(current_kid), :method => 'post', id: "save-availability", remote: true do
.form-group
= _("Date")
= select_date(Time.now + 1.day, order: [:day, :month, :year])
%br
= _("Hour")
= select_hour(Time.now )
.form-group
= submit_tag _('Save'), class: 'btn btn-blabloo btn-xs'
使用以下ajax请求:
:javascript
$("#save-availability").submit(function () {
var availability_day = $("#date_day").val();
var availability_month = $("#date_month").val();
var availability_year = $("#date_year").val();
var availability_hour = $("#date_hour").val();
var calendar = $("#calendar").fullCalendar();
$.ajax({
url: $(this).attr('action'),
type: "POST",
data: {"date_day" : availability_day, "date_month" : availability_month, "date_year" : availability_year, "date_hour" : availability_hour},
success: function(result){
alert("salvada disponibilidad");
},
error: function(xhr, textStatus, error) {
console.log("Impossible to connect");
console.log(xhr.statusText);
console.log(textStatus);
console.log(error);
}
});
});
这是我的控制器的代码:
def create
@availability = Availability.new()
@availability.availability_date = (params[:date][:day] + "/" + params[:date][:month] + "/" + params[:date][:year] + " "+ params[:date][:hour]).to_str
@availability.end_availability_date = (params[:date][:day] + "/" + params[:date][:month] + "/" + params[:date][:year] + " "+ (params[:date][:hour].to_i + 1).to_s).to_str
@availability.kid = current_kid
if @availability.save
flash[:notice] = 'Availability created successfully'
respond_to do |format|
format.json { render json: @availability.to_json, success: :ok, error: false }
end
else
flash[:error] = 'Availability not created'
end
end
一切都很好(保存记录),但是我的javascript代码上的成功代码永远不会执行,而是执行错误代码。
我在我的控制台上收到此错误:
POST http:// localhost:3000 / dashboard / kids / jean_oso / availability 150 (内部服务器错误)application.js?body = 1:8707send ?的application.js体= 1:8707jQuery.extend.ajax application.js?body = 1:8137(匿名函数) 编辑:1808jQuery.event.dispatch application.js?body = 1:5096elemData.handle application.js?body = 1:4767 无法连接编辑:1816内部服务器错误编辑:1817错误 编辑:1818内部服务器错误
我做错了什么。
提前致谢