Module: Rango::MessageMixin
- Included in:
- StackController
- Defined in:
- lib/rango/mixins/message.rb
Class Method Summary collapse
-
.included(controller) ⇒ Object
The rails-style flash messages NOTE: it’s important to include this mixin after ImplicitRendering mixin.
Instance Method Summary collapse
Class Method Details
.included(controller) ⇒ Object
The rails-style flash messages NOTE: it’s important to include this mixin after ImplicitRendering mixin
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rango/mixins/message.rb', line 8 def self.included(controller) controller.class_eval do if self.method_defined?(:context) Rango.logger.debug("Extending #{self}#context by message") # This could be in the mixin itself, but we don't want # to define it if the context method doesn't exist, so # context.respond_to?(:context) as a detection of explicit # rendering mixin and similar can work. BTW the following # doesn't work with do/end syntax. include Module.new { def context @context ||= super.merge!(message: self.) end } else Rango.logger.warn("Context #{self}#method isn't defined") end end end |
Instance Method Details
#message ⇒ Object Also known as: flash
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rango/mixins/message.rb', line 28 def @message ||= begin = request.GET[:msg] || Hash.new if .is_a?(String) .force_encoding(Encoding.default_external) elsif .is_a?(Hash) .inject(Hash.new.extend(ParamsMixin)) do |result, pair| # TODO: here is the problem, Hash.new isn't params mixin result.merge(pair[0] => pair[1].force_encoding(Encoding.default_external)) end end end end |
#redirect(uri, options = Hash.new, status = 303, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rango/mixins/message.rb', line 42 def redirect(uri, = Hash.new, status = 303, &block) # status, options = 303, status if status.is_a?(Hash) if .respond_to?(:inject) # redirect "/post", error: "Try again" # ?msg[error]="Try again" uri = .inject(uri) do |uri, pair| type, = pair uri + "?msg[#{type}]=#{}" end else # redirect "/post", "Try again" # ?msg="Try again" uri.concat("?msg=#{}") end super(uri, status) end |