2015-11-08 31 views
1

我有一個奇怪的問題(我仍然在學習rails)使用rails和flash消息。當我返回時不顯示Flash消息redirect_to

我有方法發表的link_to在我的軌道查看:

<%= link_to "<i class='fa fa-times'></i>".html_safe, email_post_path(@post.id), method: 'post' %> 

,並在我的控制器我這樣做:

def email_post 
    # do nothing 
    return redirect_to posts_path, alert: 'test flash' 
end 

問題 是工作正常(所以它重定向我正確),但不顯示閃光燈信息(問題不在於顯示的閃光燈信息,而是閃光燈[:警告]不存在)

這是wa Ÿ我顯示的提示信息:

<%= binding.pry %> #used for see if the flash is empty or not - and in this case is it! 
<% flash.each do |type, message| %> 
    <div class="flash-<%= type %>"> 
    <%= message %> 
    </div> 
<% end %> 

爲什麼不顯示在這種情況下,提示信息?

+0

刪除'return' – xlembouras

+0

如果我刪除了返回,那麼它會給我一個關於「DoubleRenderError - 在此操作中多次調用渲染和/或重定向」的錯誤。爲什麼? – Noah

回答

0

好這個問題似乎是

error: 'lol' 

有了:

alert: 'lol' 

正常工作......爲什麼?