[英]Strange flash behavior
In my project i have one place, where flash data is dissapearing. 在我的项目中,我只有一个地方,其中缺少闪存数据。 My controller (inessential code has been removed): 我的控制器(非必需代码已删除):
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
my show.htm.haml
view: 我的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"
routes for placement: 放置路线:
resource :placement, :controller => 'Placement'
and my js: 和我的js:
$(function(){
$('.placement-link').on('click', function(){
$("#placement_form").submit();
});
})
So, when i click the placement link, it redirects to my view, but with no flash. 因此,当我单击展示位置链接时,它会重定向到我的视图,但没有闪烁。 Very strange. 很奇怪。 I tryed several ways of flash assigment - the same result. 我尝试了几种闪光分配方法-相同的结果。 This behavior only in this place in my project. 此行为仅在我的项目中的此位置。
I'm using rails 3.2.8, inherited_resources 1.3.1, if it may be useful. 我使用的是Rails 3.2.8,Inherited_resources 1.3.1(如果可能有用)。
UPD. UPD。 The problem was with Javascript, after adding 添加后,问题出在Javascript上
$(function(){
$('.placement-link').on('click', function(){
$("#placement_form").submit();
});
})
everything works! 一切正常!
show.htm.haml view
link_to t("layout.placement.populate"), edit_placement_path(@placement), class: "btn btn-success placement-link pull-right
in your show
action 在你的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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.