我目前正在研究Rails中的AJAX + Bootstrap Modal。当我点击.btn_new
按钮时,我的模态没有出现问题。
它说找不到popup
。
我发现此问题仅存在于我的本地计算机上。当我尝试在我的朋友机器上克隆项目时,模态框显示正确。
我不知道这里缺少什么。
的routes.rb
resources :customers do
resources :users, only: [:index]
resources :calendars, only: [:index] do
post 'popup', on: :collection
end
end
calendars_controller.rb
def popup
if params[:daily_order_id].blank?
@exclude_kitchens = @customer.ordered_kitchens(params[:date])
@daily_order = @customer.new_default_or_blank_order(params[:date])
else
@daily_order = DailyOrder.find(params[:daily_order_id].to_i)
end
@max_pax = DailyOrder.allowable_pax(@daily_order.id, @daily_order.date,
@daily_order.kitchen_id)
respond_to :js
end
视图/日历/ index.html.erb
<%= button_tag type: 'button', 'data-date': date.strftime('%F'),
class: 'btn btn-xs btn-default btn_new' do-%>
<i class="glyphicon glyphicon-plus-sign text-primary"></i>
<%-end if date >= earliest_editable_day &&
!date.saturday? && !date.sunday? %>
<% end %>
...
<div class="modal fade" id="orderModal" tabindex="-1" role="dialog"
aria-labelledby="orderModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
</div>
</div>
</div>
视图/日历/ popup.js.erb
var order_modal = $('#orderModal')
<% if @daily_order.editable? %>
order_modal.find('.modal-content').html("<%= j render('calendars/form') %>")
<% else %>
order_modal.find('.modal-content').html(
"<%= j render partial:'order_info', locals:{ daily_order: @daily_order } %>")
<% end %>
order_modal.modal('show')
资产/ Javascript角/ calendars.js
$(document).on('click', '.btn_new', function(event){
event.preventDefault();
$.ajax({
url: location.pathname + '/popup',
type: "POST",
data: { "daily_order_id": '',
"date": new Date( $(this).attr('data-date') ) }
});
});
我的开发环境:
brew
的Mac OSX 10.11。我现在该怎么办?