我的视图中有这个电话:
$.ajax({
type: "GET",
url: "/appointments",
data: "dog_id="+ dog_id
});
我的路线:
match '/appointments', to: 'appointments#index', via: 'get'
控制器动作:
def index
@appointments = Appointment.where("dog_id = ?", params[:dog_id])
@appointments = Appointment.all
end
这两种解决方案都不起作用。当我尝试从约会中获取事件时,我收到一条消息:
undefined method `each' for nil:NilClass
我正在尝试在 View 中获取所有约会:
<% @appointments.each do |appointment| %>
任何想法这段代码有什么问题?