我的Flash消息出现两次,我的网络研究告诉我这是由于呈现和重定向显示消息。我想我需要使用flash.now []或闪光[]某处进行排序这一点,但它需要去出现在导轨上两次的Flash消息
guidelines_controller.rb
def update
@guideline = Guideline.find(params[:id])
respond_to do |format|
if @guideline.update_attributes(params[:guideline])
@guideline.update_attribute(:updated_by, current_user.id)
format.html { redirect_to @guideline, notice: 'Guideline was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "show" }
format.json { render json: @guideline.errors, status: :unprocessable_entity }
end
end
end
布局/ application.html我不能工作了.erb
<div class="container">
<% flash.each do |type, message| %>
<div class="alert <%= flash_class type %>">
<button class="close" data-dismiss="alert">x</button>
<%= message %>
</div>
<% end %>
</div>
application_helper.rb
def flash_class(type)
case type
when :alert
"alert-error"
when :notice
"alert-success"
else
""
end
end
guideline_controller.rb
def show
@guideline = Guideline.find(params[:id])
if @guideline.updated_by
@updated = User.find(@guideline.updated_by).profile_name
end
if User.find(@guideline.user_id)
@created = User.find(@guideline.user_id).profile_name
end
respond_to do |format|
format.html # show.html.erb
format.json { render json: @guideline }
end
end
尝试修复那些''<% end %>电话那里'DIV前'。我没有看到你的控制器代码有任何问题。我也不认为你需要使用'flash.discard' – jvnill 2013-03-04 01:36:34
已经编辑如上(这是你的意思?),但同样的问题正在发生。 – tessad 2013-03-04 01:40:41
不。你需要在循环之前先关闭div。尝试缩进您的代码,以便它匹配打开和关闭标签/代码 – jvnill 2013-03-04 01:45:17