0

在我的项目中,我有一个地方,闪存数据正在消失。我的控制器(无关代码已被删除):

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(); 
  });
})

一切正常!

4

1 回答 1

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
于 2012-10-04T09:59:42.357 回答