module Crystal module ControllerUrlHelper # # redirect_to # 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 = %(You are being redirected.) end # Flash need to know if we using redirect force_keeping_mode_for_flash! nil end def reload_page workspace.params.format.must == 'js' force_keeping_mode_for_flash! workspace.response.body << "window.location.reload();" end 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 protected def force_keeping_mode_for_flash! crystal[:flash].force_keeping_mode! if crystal.include? :flash end end end