我的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