Created
June 15, 2011 09:12
-
-
Save christineyen/1026769 to your computer and use it in GitHub Desktop.
Snippets of Rails source for reference in blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fields_for(record_name, record_object = nil, fields_options = {}, &block) | |
fields_options, record_object = record_object, nil if record_object.is_a?(Hash) | |
fields_options[:builder] ||= options[:builder] | |
fields_options[:parent_builder] = self | |
case record_name | |
when String, Symbol | |
if nested_attributes_association?(record_name) | |
return fields_for_with_nested_attributes(record_name, record_object, fields_options, block) | |
end | |
else | |
record_object = record_name.is_a?(Array) ? record_name.last : record_name | |
record_name = ActiveModel::Naming.param_key(record_object) | |
end | |
... | |
private | |
def nested_attributes_association?(association_name) | |
@object.respond_to?("#{association_name}_attributes=") | |
end | |
# rails/actionpack/lib/action_view/helpers/form_helper.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def redirect_to(options = {}, response_status = {}) #:doc: | |
raise ActionControllerError.new("Cannot redirect to nil!") if options.nil? | |
raise AbstractController::DoubleRenderError if response_body | |
self.status = _extract_redirect_to_status(options, response_status) | |
self.location = _compute_redirect_to_location(options) | |
self.response_body = "<html><body>You are being <a href=\"#{ERB::Util.h(location)}\">redirected</a>.</body></html>" | |
end | |
# rails/actionpack/lib/action_controller/metal/redirecting.rb |
Author
christineyen
commented
Jun 15, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment