所以假设我有这样的代码:
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>
没有骰子。我仍然没有在任何地方收到闪存消息。知道我做错了什么吗?