class RespondToController

Public Instance Methods

all_types_with_layout() click to toggle source
# File test/controller/mime_responds_test.rb, line 117
def all_types_with_layout
  respond_to do |type|
    type.js
  end
end
custom_constant_handling() click to toggle source
# File test/controller/mime_responds_test.rb, line 89
def custom_constant_handling
  respond_to do |type|
    type.html   { render :text => "HTML"   }
    type.mobile { render :text => "Mobile" }
  end
end
custom_constant_handling_without_block() click to toggle source
# File test/controller/mime_responds_test.rb, line 96
def custom_constant_handling_without_block
  respond_to do |type|
    type.html   { render :text => "HTML"   }
    type.mobile
  end
end
custom_type_handling() click to toggle source
# File test/controller/mime_responds_test.rb, line 80
def custom_type_handling
  respond_to do |type|
    type.html { render :text => "HTML"    }
    type.custom("application/crazy-xml")  { render :text => "Crazy XML"  }
    type.all  { render :text => "Nothing" }
  end
end
forced_xml() click to toggle source
# File test/controller/mime_responds_test.rb, line 47
def forced_xml
  request.format = :xml

  respond_to do |type|
    type.html { render :text => "HTML"    }
    type.xml  { render :text => "XML"     }
  end
end
handle_any() click to toggle source
# File test/controller/mime_responds_test.rb, line 103
def handle_any
  respond_to do |type|
    type.html { render :text => "HTML" }
    type.any(:js, :xml) { render :text => "Either JS or XML" }
  end
end
handle_any_any() click to toggle source
# File test/controller/mime_responds_test.rb, line 110
def handle_any_any
  respond_to do |type|
    type.html { render :text => 'HTML' }
    type.any { render :text => 'Whatever you ask for, I got it' }
  end
end
html_or_xml() click to toggle source
# File test/controller/mime_responds_test.rb, line 30
def html_or_xml
  respond_to do |type|
    type.html { render :text => "HTML"    }
    type.xml  { render :text => "XML"     }
    type.all  { render :text => "Nothing" }
  end
end
html_xml_or_rss() click to toggle source
# File test/controller/mime_responds_test.rb, line 8
def html_xml_or_rss
  respond_to do |type|
    type.html { render :text => "HTML"    }
    type.xml  { render :text => "XML"     }
    type.rss  { render :text => "RSS"     }
    type.all  { render :text => "Nothing" }
  end
end
iphone_with_html_response_type() click to toggle source
# File test/controller/mime_responds_test.rb, line 124
def iphone_with_html_response_type
  request.format = :iphone if request.env["HTTP_ACCEPT"] == "text/iphone"

  respond_to do |type|
    type.html   { @type = "Firefox" }
    type.iphone { @type = "iPhone"  }
  end
end
iphone_with_html_response_type_without_layout() click to toggle source
# File test/controller/mime_responds_test.rb, line 133
def iphone_with_html_response_type_without_layout
  request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone"

  respond_to do |type|
    type.html   { @type = "Firefox"; render :action => "iphone_with_html_response_type" }
    type.iphone { @type = "iPhone" ; render :action => "iphone_with_html_response_type" }
  end
end
js_or_html() click to toggle source
# File test/controller/mime_responds_test.rb, line 17
def js_or_html
  respond_to do |type|
    type.js   { render :text => "JS"      }
  end
end
json_or_yaml() click to toggle source
# File test/controller/mime_responds_test.rb, line 23
def json_or_yaml
  respond_to do |type|
    type.json { render :text => "JSON" }
    type.yaml { render :text => "YAML" }
  end
end
json_xml_or_html() click to toggle source
# File test/controller/mime_responds_test.rb, line 38
def json_xml_or_html
  respond_to do |type|
    type.json { render :text => 'JSON' }
    type.xml { render :xml => 'XML' }
    type.html { render :text => 'HTML' }
  end
end
just_xml() click to toggle source
# File test/controller/mime_responds_test.rb, line 56
def just_xml
  respond_to do |type|
    type.xml  { render :text => "XML" }
  end
end
made_for_content_type() click to toggle source
# File test/controller/mime_responds_test.rb, line 72
def made_for_content_type
  respond_to do |type|
    type.rss  { render :text => "RSS"  }
    type.atom { render :text => "ATOM" }
    type.all  { render :text => "Nothing" }
  end
end
rescue_action(e) click to toggle source
# File test/controller/mime_responds_test.rb, line 142
def rescue_action(e)
  raise
end
using_defaults() click to toggle source
# File test/controller/mime_responds_test.rb, line 62
def using_defaults
  respond_to do |type|
    type.js
  end
end
using_defaults_with_type_list() click to toggle source
# File test/controller/mime_responds_test.rb, line 68
def using_defaults_with_type_list
  respond_to(:js)
end

Protected Instance Methods

set_layout() click to toggle source
# File test/controller/mime_responds_test.rb, line 147
def set_layout
  if ["all_types_with_layout", "iphone_with_html_response_type"].include?(action_name)
    "respond_to/layouts/standard"
  elsif action_name == "iphone_with_html_response_type_without_layout"
    "respond_to/layouts/missing"
  end
end