Module: GoToParam

Defined in:
lib/go_to_param.rb,
lib/go_to_param/version.rb

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



5
6
7
8
9
# File 'lib/go_to_param.rb', line 5

def self.included(klass)
  klass.helper_method :hidden_go_to_tag, :hidden_go_to_here_tag,
    :go_to_params, :go_to_here_params,
    :go_to_path, :go_to_path_or
end

Instance Method Details

#go_to_here_params(additional_query_params = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/go_to_param.rb', line 23

def go_to_here_params(additional_query_params = {})
  path = go_to_here_path(additional_query_params)

  if path
    { go_to: path }
  else
    {}
  end
end

#go_to_params(other_params = {}) ⇒ Object



19
20
21
# File 'lib/go_to_param.rb', line 19

def go_to_params(other_params = {})
  { go_to: go_to_path }.merge(other_params)
end

#go_to_pathObject



33
34
35
36
37
38
39
40
# File 'lib/go_to_param.rb', line 33

def go_to_path
  # Avoid phishing redirects.
  if go_to_param_value.to_s.start_with?("/")
    go_to_param_value
  else
    nil
  end
end

#go_to_path_or(default) ⇒ Object



42
43
44
# File 'lib/go_to_param.rb', line 42

def go_to_path_or(default)
  go_to_path || default
end

#hidden_go_to_here_tag(additional_query_params = {}) ⇒ Object



15
16
17
# File 'lib/go_to_param.rb', line 15

def hidden_go_to_here_tag(additional_query_params = {})
  view_context.hidden_field_tag :go_to, go_to_here_params(additional_query_params)[:go_to]
end

#hidden_go_to_tagObject



11
12
13
# File 'lib/go_to_param.rb', line 11

def hidden_go_to_tag
  view_context.hidden_field_tag :go_to, go_to_path
end