def create
@addpost = Post.new params[:data]
if @addpost.save
flash[:notice] = \"Post has been saved successfully.\"
redirect_to posts_path
e
flash.now
with render
is what you're looking for.
flash.now[:notice] = "Post can not be saved, please enter information."
render :new
Also instead of
flash[:notice] = "Post has been saved successfully."
redirect_to posts_path
you can just write
redirect_to posts_path, :notice => "Post has been saved successfully."
and it will do the same thing. It works only with redirect_to
though, not with render!