それでは、次のようなコードがあるとしましょう。
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>
サイコロはありません。私はまだどこにもフラッシュメッセージを受け取っていません。私が間違っていることは何か分かりますか?