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
34 35 36 37 38 39 40 |
# File 'lib/backable/controller_concern.rb', line 34 def backable_back_path( fallback=nil ) back = backable_history.last fallback = Rails.env.development? ? "http://watbenjedan.nl/" : :back 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
29 30 31 |
# File 'lib/backable/controller_concern.rb', line 29 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
14 15 16 17 |
# File 'lib/backable/controller_concern.rb', line 14 def backable_param( history=nil) history ||= (backable_history + backable_future) history.map{|bi| bi.to_s }.join("|") end |
#backable_push(path) ⇒ Object
43 44 45 46 |
# File 'lib/backable/controller_concern.rb', line 43 def backable_push(path) path = polymorphic_path(path) if !path.kind_of?( String ) backable_future << "#{path}" end |
#backable_url_for(link_options, extra_options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/backable/controller_concern.rb', line 49 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 |