在我的项目中,我有一个地方,闪存数据正在消失。我的控制器(无关代码已被删除):
class PlacementController < InheritedResources::Base
defaults resource_class: Reservation, collection_name: 'reservations', instance_name: 'reservation'
before_filter :check_user_buildings
def show
end
def update
flash[:notice] = "1"
redirect_to placement_path(type: "entry")
end
protected
def check_user_buildings
if current_user.building_ids.empty?
redirect_to :back, alert: t("layout.placement.no_building")
end
end
end
我的show.htm.haml
看法:
= render :partial => 'layouts/flash', :locals => {:flash => flash}
= link_to t("layout.placement.populate"), "#", class: "btn btn-success placement-link pull-right"
= form_tag placement_path, method: :put, id: "placement_form" do
= "ttt"
放置路线:
resource :placement, :controller => 'Placement'
和我的js:
$(function(){
$('.placement-link').on('click', function(){
$("#placement_form").submit();
});
})
所以,当我点击展示位置链接时,它会重定向到我的视图,但没有闪光灯。很奇怪。我尝试了几种快速分配方式——结果相同。这种行为只出现在我项目的这个地方。
我正在使用 rails 3.2.8,inherited_resources 1.3.1,如果它可能有用的话。
UPD。添加后,问题出在Javascript
$(function(){
$('.placement-link').on('click', function(){
$("#placement_form").submit();
});
})
一切正常!