From d738a206e55b1e9fa584e3ad05ce3e6695c98eb3 Mon Sep 17 00:00:00 2001 From: Matthew Bass Date: Wed, 12 Nov 2008 14:35:51 -0500 Subject: [PATCH] first pass at flash messages, unfortunately they don't work well due to caching --- app/controllers/subscriber_actions_controller.rb | 16 ++++++++-------- app/models/spreedly_tags.rb | 11 ++++++++++- app/views/subscriber/_notice.html.erb | 4 ++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/controllers/subscriber_actions_controller.rb b/app/controllers/subscriber_actions_controller.rb index 1d60e02..6afd655 100644 --- a/app/controllers/subscriber_actions_controller.rb +++ b/app/controllers/subscriber_actions_controller.rb @@ -7,17 +7,17 @@ def login login_as subscriber redirect_to "/subscriber" else - flash[:notice] = "Unable to login." - redirect_to "/subscriber/login" + notice = "Unable to login." + redirect_to "/subscriber/login?notice=#{notice}" end end def logout if logged_in? cookies["subscriber"] = nil - flash[:notice] = "You have been logged out." + notice = "You have been logged out." end - redirect_to "/subscriber/login" + redirect_to "/subscriber/login?notice=#{notice}" end def register @@ -26,15 +26,15 @@ def register login_as @subscriber redirect_to "/subscriber" else - flash[:notice] = "One or more validation errors occured." - redirect_to "/subscriber/register" + notice = "One or more validation errors occured." + redirect_to "/subscriber/register?notice=#{notice}" end end def changed if params[:return] - flash[:notice] = "Your account has been refreshed." - redirect_to "/subscriber" + notice = "Your subscription status has been refreshed." + redirect_to "/subscriber?notice=#{notice}" else ids = (params[:subscriber_ids] || "").split(",") subscribers = Subscriber.find(:all, :conditions => ["id in (?)", ids]) diff --git a/app/models/spreedly_tags.rb b/app/models/spreedly_tags.rb index 2430d0f..2821d27 100644 --- a/app/models/spreedly_tags.rb +++ b/app/models/spreedly_tags.rb @@ -3,6 +3,15 @@ module SpreedlyTags include ActionController::UrlWriter default_url_options[:host] = "localhost:3000" + tag "flash" do |tag| + tag.expand + end + + tag "flash:notices" do |tag| + notice = tag.locals.page.request.parameters["notice"] + "#{notice}" unless notice.blank? + end + ## subscribers tag "subscribers" do |tag| @@ -41,7 +50,7 @@ module SpreedlyTags tag "subscriber:refresh" do |tag| s = tag.locals.subscriber - "#{tag.attr['title'] || 'Refresh Subscription'}" + "#{tag.attr['title'] || 'Refresh Subscription Status'}" end tag "subscriber:subscription" do |tag| diff --git a/app/views/subscriber/_notice.html.erb b/app/views/subscriber/_notice.html.erb index 6761d62..ca7f793 100644 --- a/app/views/subscriber/_notice.html.erb +++ b/app/views/subscriber/_notice.html.erb @@ -1,3 +1,3 @@ -<% unless flash[:notice].blank? -%> - <%= flash[:notice] %> +<% unless params[:notice].blank? -%> + <%=h params[:notice] %> <% end -%> \ No newline at end of file