Rails: Flash Messages not appearing anywhere -
so let's have code this:
class postscontroller < inheritedresources::base # add before_filter here , devise should handle redirection if user 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 voted" end end end neither of messages "you have voted successfully" or "you have voted" being shown.
in view have:
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 song!', vote_up_post_path(@post), :method => :post) %></p> <p><id="notice"><%= notice %></p> no dice. i'm still not getting flash messages anywhere. idea i'm doing wrong?
you should set flash before redirect_to
and in view
<p> <%= flash[:success] unless flash[:success].blank? %> <%= flash[:error] unless flash[:error].blank? %> </p> you can check link
Comments
Post a Comment