0

私のプロジェクトでは、フラッシュデータが消えている場所が 1 つあります。私のコントローラー(不要なコードは削除されました):

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 を使用しています。

アップデート。追加した後、問題は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 に答える