在我的项目中,我有一个地方,闪存数据消失了。 我的控制器(已删除非必要代码):
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();
});
})
因此,当我点击展示位置链接时,它会重定向到我的视图,但没有闪存。很奇怪。我尝试了几种flash分配方法 - 结果相同。此行为仅在我的项目中的这个位置。
我正在使用rails 3.2.8,inherited_resources 1.3.1,如果它可能有用。
UPD。添加
后,问题出在Javascript上$(function(){
$('.placement-link').on('click', function(){
$("#placement_form").submit();
});
})
一切正常!
答案 0 :(得分:0)
show.htm.haml view
link_to t("layout.placement.populate"), edit_placement_path(@placement), class: "btn btn-success placement-link pull-right
show
行动
def show
@placement = Placement.find(params[:id])
end
def edit
@placement = Placement.find(params[:id])
end
def update
@placement = Placement.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to placement_path(tyle: "entry"), notice: 'flash message' }
else
format.html { render action: "edit" }
end
end
end