Skip to content

Instantly share code, notes, and snippets.

@christineyen
Created June 15, 2011 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christineyen/1026769 to your computer and use it in GitHub Desktop.
Save christineyen/1026769 to your computer and use it in GitHub Desktop.
Snippets of Rails source for reference in blog
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
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
@christineyen
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment