Module: Crystal::ControllerUrlHelper

Defined in:
lib/crystal/html/controller_helpers/controller_url_helper.rb

Instance Method Summary collapse

Instance Method Details

#redirect_to(*args) ⇒ Object

redirect_to



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/crystal/html/controller_helpers/controller_url_helper.rb', line 6

def redirect_to *args
  params, response = workspace.params, workspace.response
  params.format.must_be.in 'html', 'js'                
  
  url = special_url(*args) || url_for(*args)
  
  if params.format == 'js'
    response.body << "window.location = '#{url}';"
  else
    response.status = 301
    response.headers['Location'] = url        
    response.body = %(<html><body>You are being <a href="#{h(url)}">redirected</a>.</body></html>)
  end
  
  # Flash need to know if we using redirect
  force_keeping_mode_for_flash!
  
  nil
end

#reload_pageObject



26
27
28
29
30
31
# File 'lib/crystal/html/controller_helpers/controller_url_helper.rb', line 26

def reload_page
  workspace.params.format.must == 'js'
  
  force_keeping_mode_for_flash!
  workspace.response.body << "window.location.reload();"
end

#special_url(*args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/crystal/html/controller_helpers/controller_url_helper.rb', line 33

def special_url *args
  return nil unless args.last.empty?
          
  case args.first.to_s
  when 'back'
    workspace.request.env["HTTP_REFERER"] || 'javascript:history.back()'
  when '#' then
    '#'
  else
    nil
  end
end