【发布时间】:2012-03-06 13:47:13
【问题描述】:
这让我发疯了。我有一个新的Rails 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:
我做错了什么?
【问题讨论】:
标签: ruby-on-rails-3 erb