2012-03-06 22 views
2

這讓我瘋狂。我有一個新的Rails 3.2.2資產管理應用程序。在Rails中無法使用的Flash消息3.2.2

這裏是我的控制器:

class AssetsController < ApplicationController 
    respond_to :html, :json, :xml 

    def index 
    respond_with(@assets = Asset.all) 
    end 

    def show 
    @asset = Asset.find(params[:id]) 
    respond_with @asset 
    end 

    def new 
    @asset = Asset.new 
    respond_with @asset 
    end 

    def create 
    @asset = Asset.new(params[:asset]) 
    if @asset.save 
     flash[:notice] = "Asset created successfully" 
    end 
    respond_with @asset 
    end 

    def edit 
    @asset = Asset.find(params[:id]) 
    respond_with @asset 
    end 

    def update 
    @asset = Asset.find(params[:id]) 
    if @asset.update_attributes(params[:asset]) 
     flash[:notice] = "Asset updated successfully" 
    end 
    respond_with @asset 
    end 

    def destroy 
    # tbd... 
    end 

end 

這裏是我的application.html.erb

<% flash.each do |name, msg| %> 
    <div class="alert alert-<%= name == :notice ? "success" : "error" %>"> 
     <%= msg %> 
    </div> 
<% end %> 

一部分。但是,閃光燈總是空的。即使在資產模型更新成功之後。

當調試flash對象,這就是我得到:

--- !ruby/object:ActionDispatch::Flash::FlashHash 
used: !ruby/object:Set 
    hash: {} 
closed: false 
flashes: {} 
now: 

我在做什麼錯?

回答

0

你的代碼對我來說看起來很好。這個Rails上的bug report看起來與你的非常相似,所以它可能值得升級到最新版本的Rails? (據說Bug在過去24小時內剛剛修好)

+0

好吧,這是搞砸了。我剛剛創建了另一個資產(位置),並且閃存消息與它一起工作!但不是「資產」。我升級到Rails 3.2.2。捆綁更新。並將兩個控制器都改爲相同的(好吧,除了資產和位置)。爲什麼它會在地點而不是資產上工作?啊。 – cbmeeks 2012-03-06 16:04:39

+0

我的猜測是'資產'可能是Rails 3.2中的一個保留字。除了這個線程,我找不到任何證據來支持這個:http://stackoverflow.com/questions/8186183/routing-issue-with-rails-3 – 2012-03-06 16:31:10

相關問題