Module: Backable::ControllerConcern
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/backable/controller_concern.rb
Instance Method Summary collapse
- #backable_back_path(fallback = nil) ⇒ Object
- #backable_future ⇒ Object
- #backable_history ⇒ Object
- #backable_param(history = nil) ⇒ Object
- #backable_push(path) ⇒ Object
- #backable_url_for(link_options, extra_options = {}) ⇒ Object
Instance Method Details
#backable_back_path(fallback = nil) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/backable/controller_concern.rb', line 32 def backable_back_path( fallback=nil ) back = backable_history.last fallback = Backable.fallback_url return fallback unless back back_param = backable_param( backable_history[0..-2] ) back.index('?') ? "#{back}&back=#{CGI::escape(back_param)}" : "#{back}?back=#{CGI::escape(back_param)}" end |
#backable_future ⇒ Object
28 29 30 |
# File 'lib/backable/controller_concern.rb', line 28 def backable_future @backable_future ||= [] end |
#backable_history ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/backable/controller_concern.rb', line 20 def backable_history @backable_history ||= begin (params[:back] || "").split('|').map do |v| v end end end |
#backable_param(history = nil) ⇒ Object
15 16 17 18 |
# File 'lib/backable/controller_concern.rb', line 15 def backable_param( history=nil) history ||= (backable_history + backable_future) history.map{ |bi| bi.to_s }.join("|") end |
#backable_push(path) ⇒ Object
41 42 43 44 |
# File 'lib/backable/controller_concern.rb', line 41 def backable_push(path) path = polymorphic_path(path) if !path.kind_of?( String ) backable_future << path.to_s end |
#backable_url_for(link_options, extra_options = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/backable/controller_concern.rb', line 46 def backable_url_for( , = {} ) args = .merge( back: backable_param ) # support for strings if .kind_of?( String ) url = url << ( .index('?') ? '&' : '?' ) url << args.to_query url else polymorphic_url( , args ) end end |