Module: Ajax::ActionController::Rails2
- Defined in:
- lib/ajax/action_controller.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#redirect_to_full_url_with_ajax(url, status) ⇒ Object
Redirect to hashed URLs unless the path is excepted.
-
#render_with_ajax(options = nil, extra_options = {}, &block) ⇒ Object
Intercept rendering to customize the headers and layout handling.
Class Method Details
.included(klass) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/ajax/action_controller.rb', line 47 def self.included(klass) klass.class_eval do alias_method_chain :redirect_to_full_url, :ajax alias_method_chain :render, :ajax end end |
Instance Method Details
#redirect_to_full_url_with_ajax(url, status) ⇒ Object
Redirect to hashed URLs unless the path is excepted.
Store the URL that we are redirecting to in the session. If we then have a request for the root URL we know to render this URL instead.
If redirecting back to the referer, use the referer in the Ajax-Info header because it includes the hashed part of the URL. Otherwise the referer is always the root url.
For AJAX requests, respond with an AJAX-suitable redirect.
This method only applies to Rails < 3
69 70 71 72 73 |
# File 'lib/ajax/action_controller.rb', line 69 def redirect_to_full_url_with_ajax(url, status) if !_ajax_redirect(url) redirect_to_full_url_without_ajax(url, status) end end |
#render_with_ajax(options = nil, extra_options = {}, &block) ⇒ Object
Intercept rendering to customize the headers and layout handling
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ajax/action_controller.rb', line 78 def render_with_ajax( = nil, = {}, &block) return render_without_ajax(, , &block) unless Ajax.is_enabled? original_args = [, ] if request.xhr? # Options processing taken from ActionController::Base#render if .nil? = { :template => default_template, :layout => true } elsif == :update = .merge({ :update => true }) elsif .is_a?(String) || .is_a?(Symbol) case .to_s.index('/') when 0 [:file] = when nil [:action] = else [:template] = end = elsif !.is_a?(Hash) [:partial] = = end default = pick_layout() default = default.path_without_format_and_extension unless default.nil? if ajax_layout = _layout_for_ajax(default) if ajax_layout = _find_ajax_layout(ajax_layout) [:layout] = ajax_layout.path_without_format_and_extension end end end render_without_ajax(, , &block) end |