Strange flash behavior

142 Views Asked by At

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:

= 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:

$(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.

UPD. The problem was with Javascript, after adding

$(function(){
  $('.placement-link').on('click', function(){ 
    $("#placement_form").submit(); 
  });
})

everything works!

1

There are 1 best solutions below

0
On
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

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