2012-10-04 57 views
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(); 
    }); 
}) 

因此,當我點擊放置鏈接時,它重定向到我的視圖,但沒有閃光。很奇怪。我嘗試了幾種Flash分配方式 - 結果相同。這種行爲只在我的項目中的這個地方。

我使用rails 3.2.8,inherited_resources 1.3.1,如果它可能有用。

UPD。問題出在Javascript後,加入後

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

一切正常!

+0

而讓Flash消失了,我說。它很古老,想要永遠離開。 – amn

+1

@amn,這不是關於Adobe Flash,它是Ruby on Rails框架中的flash消息=) –

+0

@DenisTataurov stackoverflow不知道你的意圖,並且存在rails-flash標記 – nurettin

回答

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

沒有幫助=( –

+0

我更新了代碼試試,刪除js功能 –

+0

找到了解決辦法,看UPD –