【发布时间】:2013-11-25 15:04:34
【问题描述】:
我已经使用fullcalendar assets gem 列出日历中的所有事件,我尝试根据我的需要修改日历,但对于这种情况,我感到困惑。
我用过https://github.com/bokmann/rails3_fullcalendar
场景: 我必须过滤掉日历中特定工作人员的所有约会。所以在我的约会控制器中,我以这种方式列出了所有约会。
@appointments = @client.appointments
它列出了客户的所有约会,所以现在我要根据我列出客户所有工作人员的下拉按钮的选择再次过滤掉约会。因此,根据所选的工人,它将显示该特定所选工人的约会。
代码尝试
1. Rails 方式
首先,我尝试使用 rails 方式,我需要将工作人员的 id 从下拉列表传递到控制器,我使用的下拉代码:
<%= form_tag appointments_path do %>
<%= select_tag(:worker_id, options_from_collection_for_select(@client.workers, :id, :alias), :include_blank =>true)%>
<%=submit_tag "Display"%>
<% end %>
但我不知道在控制器中传递什么来获取记录。
2。 JS方式
<%= select_tag(:worker_id, options_from_collection_for_select(@client.workers, :id, :alias), :include_blank =>true),:onchange => 'a(this.value)'%>
calendar.js
function a(pointer){
var intWorkerId = pointer;
alert(intWorkerId);
$.ajax({
url:'/appointments',
dataType: "json",
data:({
id:intWorkerId
}),
type:'get',
success:function(result){
alert(result);
$('#content').html(result);
console.log(1);
}
});
}
当我尝试打印值并尝试从该 id 打印值时,我如何在控制器中获取工人的 id,这是正确的,但我不知道如何继续。
Appointment.rb
def as_json(options = {})
{
:id => self.id,
:title => self.title,
:description => self.description || "",
:start => appointment_start_time.rfc822,
:end => appointment_end_time.rfc822,
:allDay => self.all_day,
:recurring => false,
:url => Rails.application.routes.url_helpers.appointment_path(id)
#:color => "red"
}
Appointment_controller.rb
if params[:id]
#@appointments = @client.workers.params[:id].appointments
#p "*********id values****#{params[:id]}"
#worker = Worker.find(params[:id])
#p"***** #{worker.alias}"
#@appointments = worker.appointments
#p "******* #{@appointments.count}"
p "*******hello id is here*******"
else
@appointments = "hello"
p "*******hello id is not here*******"
end
我已经尝试了所有可能的组合,但无法获得结果。请帮帮我。
谢谢
【问题讨论】:
标签: javascript ruby-on-rails ruby ruby-on-rails-3 fullcalendar