Skip to content

Commit

Permalink
first pass at flash messages, unfortunately they don't work well due …
Browse files Browse the repository at this point in the history
…to caching
  • Loading branch information
Matthew Bass committed Nov 12, 2008
1 parent 04dad76 commit d738a20
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
16 changes: 8 additions & 8 deletions app/controllers/subscriber_actions_controller.rb
Expand Up @@ -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
Expand All @@ -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])
Expand Down
11 changes: 10 additions & 1 deletion app/models/spreedly_tags.rb
Expand Up @@ -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"]
"<span style=\"font-weight:bold; color:red\">#{notice}</span>" unless notice.blank?
end

## subscribers

tag "subscribers" do |tag|
Expand Down Expand Up @@ -41,7 +50,7 @@ module SpreedlyTags

tag "subscriber:refresh" do |tag|
s = tag.locals.subscriber
"<a href=\"/subscriber_actions/changed?subscriber_ids=#{s.id}&return=true\">#{tag.attr['title'] || 'Refresh Subscription'}</a>"
"<a href=\"/subscriber_actions/changed?subscriber_ids=#{s.id}&return=true\">#{tag.attr['title'] || 'Refresh Subscription Status'}</a>"
end

tag "subscriber:subscription" do |tag|
Expand Down
4 changes: 2 additions & 2 deletions app/views/subscriber/_notice.html.erb
@@ -1,3 +1,3 @@
<% unless flash[:notice].blank? -%>
<span style="color:red"><%= flash[:notice] %></span>
<% unless params[:notice].blank? -%>
<span style="color:red"><%=h params[:notice] %></span>
<% end -%>

0 comments on commit d738a20

Please sign in to comment.