所以我們可以說我有這樣的代碼:Rails的:即顯信息不會出現在任何位置
class PostsController < InheritedResources::Base
# Add before_filter here and devise should handle the redirection if the user is not signed in.
before_filter :authenticate_user!, only: [:vote_up]
def vote_up
begin
current_user.vote_for(@post = Post.find(params[:id]))
redirect_to [@post]
flash[:success] = "You have voted successfully"
rescue ActiveRecord::RecordInvalid
redirect_to [@post]
flash[:error] = "You have already voted"
end
end
end
無論是消息「您已成功投」或「您已投票」被顯示。
在我看來,我有:
enter code here
<p id="notice"><%= notice %></p>
<%= @post.embed .html_safe %>
<header>
<h7><%= @post.name %></h7>
</header>
<h8><%= @post.title %></h8>
<article>
<%= @post.content .html_safe %>
<p>
<%= link_to 'Back', posts_path %> |
<%= link_to('Vote for this song!', vote_up_post_path(@post), :method => :post) %></p>
<p><id="notice"><%= notice %></p>
沒有骰子。我仍然沒有得到任何地方的Flash消息。任何想法我做錯了什麼?
看起來你回答第一個也是最徹底的。有效!那幾乎是最後一個障礙!謝謝。 –
但是,爲什麼'redirect_to @user,注意:「成功」'工作而不是'redirect_to @user,成功:「成功」'? –